Skip to content

Commit 8a8b2ce

Browse files
steveklabnikManishearth
authored andcommitted
Document {:.*}
Fixes #22927
1 parent 351721c commit 8a8b2ce

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/libcollections/fmt.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,18 @@
105105
//! hexadecimal as well as an
106106
//! octal.
107107
//!
108-
//! There are various parameters which do require a particular type, however.
109-
//! Namely if the syntax `{:.*}` is used, then the number of characters to print
110-
//! precedes the actual object being formatted, and the number of characters
111-
//! must have the type `usize`. Although a `usize` can be printed with `{}`, it is
112-
//! illegal to reference an argument as such. For example this is another
108+
//! There are various parameters which do require a particular type, however. Namely, the `{:.*}`
109+
//! syntax, which sets the number of numbers after the decimal in floating-point types:
110+
//!
111+
//! ```
112+
//! let formatted_number = format!("{:.*}", 2, 1.234567);
113+
//!
114+
//! assert_eq!("1.23", formatted_number)
115+
//! ```
116+
//!
117+
//! If this syntax is used, then the number of characters to print precedes the actual object being
118+
//! formatted, and the number of characters must have the type `usize`. Although a `usize` can be
119+
//! printed with `{}`, it is illegal to reference an argument as such. For example this is another
113120
//! invalid format string:
114121
//!
115122
//! ```text

0 commit comments

Comments
 (0)