diff options
| author | Steve Klabnik <steve@steveklabnik.com> | 2015-03-18 19:15:26 -0400 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2015-03-19 08:24:39 +0530 |
| commit | 8a8b2cecbc1fab7ffa4a20efb6dc4deed876571e (patch) | |
| tree | 1509346604fada936c2302d6d454e9a565121151 /src | |
| parent | 351721cde6534d0a20bda8cbacc0019fca6caf3f (diff) | |
| download | rust-8a8b2cecbc1fab7ffa4a20efb6dc4deed876571e.tar.gz rust-8a8b2cecbc1fab7ffa4a20efb6dc4deed876571e.zip | |
Document {:.*}
Fixes #22927
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcollections/fmt.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/libcollections/fmt.rs b/src/libcollections/fmt.rs index fbd07e48a84..d2abb59ffab 100644 --- a/src/libcollections/fmt.rs +++ b/src/libcollections/fmt.rs @@ -105,11 +105,18 @@ //! hexadecimal as well as an //! octal. //! -//! There are various parameters which do require a particular type, however. -//! Namely if the syntax `{:.*}` is used, then the number of characters to print -//! precedes the actual object being formatted, and the number of characters -//! must have the type `usize`. Although a `usize` can be printed with `{}`, it is -//! illegal to reference an argument as such. For example this is another +//! There are various parameters which do require a particular type, however. Namely, the `{:.*}` +//! syntax, which sets the number of numbers after the decimal in floating-point types: +//! +//! ``` +//! let formatted_number = format!("{:.*}", 2, 1.234567); +//! +//! assert_eq!("1.23", formatted_number) +//! ``` +//! +//! If this syntax is used, then the number of characters to print precedes the actual object being +//! formatted, and the number of characters must have the type `usize`. Although a `usize` can be +//! printed with `{}`, it is illegal to reference an argument as such. For example this is another //! invalid format string: //! //! ```text |
