-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Improve document for std::fmt
to format float type
#112760
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -273,6 +273,37 @@ | |||||
//! Hello, ` 123` has 3 right-aligned characters | ||||||
//! ``` | ||||||
//! | ||||||
//! For the floating-point type, it employs the | ||||||
//! [roundTiesToEven](https://en.m.wikipedia.org/wiki/Rounding#Rounding_half_to_even) convention: | ||||||
Comment on lines
+276
to
+277
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unlikely to be the most appropriate link because the subsection you linked to is describing the operation of rounding a float to an integer, which is different in general from formatting a float to a particular precision. The text even calls this out: a "more sophisticated mode [is] used when rounding to significant figures". |
||||||
//! | ||||||
//! ``` | ||||||
//! println!("{:.0}", 12.5f64); // 12 | ||||||
//! println!("{:.0}", 12.3f64); // 12 | ||||||
//! println!("{:.0}", 11.6f64); // 12 | ||||||
//! println!("{:.0}", 11.5f64); // 12 | ||||||
//! println!("{:.0}", 11.4f64); // 11 | ||||||
//! println!("{:.0}", 10.5f64); // 10 | ||||||
//! println!("{:.0}", 9.5f64); // 10 | ||||||
//! println!("{:.0}", 8.5f64); // 8 | ||||||
//! println!("{:.0}", 7.5f64); // 8 | ||||||
//! println!("{:.0}", -7.5f64); // -8 | ||||||
//! println!("{:.0}", -8.5f64); // -8 | ||||||
//! println!("{:.0}", -9.5f64); // -10 | ||||||
//! println!("{:.0}", -10.5f64);// -10 | ||||||
//! println!("{:.0}", -11.4f64);// -11 | ||||||
//! println!("{:.0}", -11.5f64);// -12 | ||||||
//! println!("{:.0}", -11.6f64);// -12 | ||||||
//! println!("{:.0}", -12.5f64);// -12 | ||||||
//! println!("{:.0}", -12.6f64);// -13 | ||||||
//! | ||||||
//! println!("{:.1}", 3.33f64); // 3.3 | ||||||
//! println!("{:.1}", -3.33f64);// -3.3 | ||||||
//! println!("{:.1}", -3.55f64);// -3.5 | ||||||
//! println!("{:.1}", 4.54f64); // 4.5 | ||||||
//! println!("{:.1}", 4.55f64); // 4.5 | ||||||
//! println!("{:.1}", 4.56f64); // 4.6 | ||||||
Comment on lines
+280
to
+304
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like an extremely excessive number of examples. Can |
||||||
//! ``` | ||||||
//! | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is already a paragraph above which describes how precision applies to floating point types. It would make more sense to me to explain the rounding directly in that paragraph. Lines 209 to 210 in bf0e22b
|
||||||
//! ## Localization | ||||||
//! | ||||||
//! In some programming languages, the behavior of string formatting functions | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the name "roundTiesToEven" refer to exactly? I did not find that anywhere in the link.