Skip to content

Commit 69fe2a7

Browse files
committed
Add examples by @pnkfelix to fmt precision
Fixes #24656
1 parent 3860240 commit 69fe2a7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/libcollections/fmt.rs

+15
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,21 @@
407407
//! For floating-point types, this indicates how many digits after the decimal
408408
//! point should be printed.
409409
//!
410+
//! By example, these:
411+
//!
412+
//! ```
413+
//! println!("Hello {1} is {2:.0$}", 5, "x", 0.01);
414+
//! println!("Hello {0} is {2:.1$}", "x", 5, 0.01);
415+
//! println!("Hello {} is {:.*}", "x", 5, 0.01);
416+
//! println!("Hello {} is {2:.*}", "x", 5, 0.01);
417+
//! ```
418+
//!
419+
//! All print the same thing:
420+
//!
421+
//! ```text
422+
//! Hello x is 0.01000
423+
//! ```
424+
//!
410425
//! # Escaping
411426
//!
412427
//! The literal characters `{` and `}` may be included in a string by preceding

0 commit comments

Comments
 (0)