Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(float) fix some rounding errors when showing as str #2488

Closed
wants to merge 1 commit into from

Conversation

killerswan
Copy link
Contributor

This seems to fix issue #1876, and some of the superficial parts of
issue #1375. The #fmt macro and the to_str functions will round,
rather than truncate, floats as strings.

Other issues remain, and I wrote more code here than intended, but the
following should pass now.

fn x() {
   assert "3.1416"      == #fmt["%.4f", 3.14159];
   assert "3"           == #fmt["%.0f", 3.14159];
   assert "99"          == #fmt["%.0f", 98.5];
   assert "7.0000"      == #fmt["%.4f", 6.999999999];
   assert "3.141590000" == #fmt["%.9f", 3.14159];
}

This seems to fix issue rust-lang#1876, and some of the superficial parts of
issue rust-lang#1375.  The #fmt macro and the to_str functions will round,
rather than truncate, floats as strings.

Other issues remain, and I wrote more code here than intended, but the
following should pass now.

```
fn x() {
   assert "3.1416"      == #fmt["%.4f", 3.14159];
   assert "3"           == #fmt["%.0f", 3.14159];
   assert "99"          == #fmt["%.0f", 98.5];
   assert "7.0000"      == #fmt["%.4f", 6.999999999];
   assert "3.141590000" == #fmt["%.9f", 3.14159];
}
```
@brson
Copy link
Contributor

brson commented Jun 2, 2012

Thanks!

@brson brson closed this Jun 2, 2012
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants