Skip to content

Commit ca63ba9

Browse files
authored
Rollup merge of rust-lang#120967 - LeoDog896:master, r=cuviper
docs: mention round-to-even in precision formatting _Note_: Not quite sure exactly how to format this documentation. Mentions round-to-even usage in precision formatting. (should this also be mentioned in `f64::round`?) From rust-lang#70336
2 parents b9a7dbf + fa02631 commit ca63ba9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

alloc/src/fmt.rs

+16
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,22 @@
278278
//! Hello, ` 123` has 3 right-aligned characters
279279
//! ```
280280
//!
281+
//! When truncating these values, Rust uses [round half-to-even](https://en.wikipedia.org/wiki/Rounding#Rounding_half_to_even),
282+
//! which is the default rounding mode in IEEE 754.
283+
//! For example,
284+
//!
285+
//! ```
286+
//! print!("{0:.1$e}", 12345, 3);
287+
//! print!("{0:.1$e}", 12355, 3);
288+
//! ```
289+
//!
290+
//! Would return:
291+
//!
292+
//! ```text
293+
//! 1.234e4
294+
//! 1.236e4
295+
//! ```
296+
//!
281297
//! ## Localization
282298
//!
283299
//! In some programming languages, the behavior of string formatting functions

0 commit comments

Comments
 (0)