File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed
Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments