|
402 | 402 | //!
|
403 | 403 | //! For floating-point types, this indicates how many digits after the decimal point should be
|
404 | 404 | //! printed.
|
405 |
| -//! |
| 405 | +//! |
406 | 406 | //! There are three possible ways to specify the desired `precision`:
|
407 | 407 | //!
|
408 |
| -//! There are three possible ways to specify the desired `precision`: |
409 |
| -//! 1. An integer `.N`, |
| 408 | +//! There are three possible ways to specify the desired `precision`: |
| 409 | +//! 1. An integer `.N`, |
410 | 410 | //! 2. an integer followed by dollar sign `.N$`, or
|
411 | 411 | //! 3. an asterisk `.*`.
|
412 | 412 | //!
|
|
418 | 418 | //! the first input holds the `usize` precision, and the second holds the value to print. Note
|
419 | 419 | //! that in this case, if one uses the format string `{<arg>:<spec>.*}`, then the `<arg>` part
|
420 | 420 | //! refers to the *value* to print, and the `precision` must come in the input preceding `<arg>`.
|
421 |
| -//! |
422 |
| -//! For example, these: |
| 421 | +//! |
| 422 | +//! For example, these: |
423 | 423 | //!
|
424 | 424 | //! ```
|
425 | 425 | //! // Hello {arg 0 (x)} is {arg 1 (0.01} with precision specified inline (5)}
|
426 | 426 | //! println!("Hello {0} is {1:.5}", "x", 0.01);
|
427 |
| -//! |
| 427 | +//! |
428 | 428 | //! // Hello {arg 1 (x)} is {arg 2 (0.01} with precision specified in arg 0 (5)}
|
429 | 429 | //! println!("Hello {1} is {2:.0$}", 5, "x", 0.01);
|
430 | 430 | //!
|
431 | 431 | //! // Hello {arg 0 (x)} is {arg 2 (0.01} with precision specified in arg 1 (5)}
|
432 | 432 | //! println!("Hello {0} is {2:.1$}", "x", 5, 0.01);
|
433 |
| -//! |
| 433 | +//! |
434 | 434 | //! // Hello {next arg (x)} is {second of next two args (0.01} with precision
|
435 | 435 | //! // specified in first of next two args (5)}
|
436 | 436 | //! println!("Hello {} is {:.*}", "x", 5, 0.01);
|
437 |
| -//! |
| 437 | +//! |
438 | 438 | //! // Hello {next arg (x)} is {arg 2 (0.01} with precision
|
439 | 439 | //! // specified in its predecessor (5)}
|
440 | 440 | //! println!("Hello {} is {2:.*}", "x", 5, 0.01);
|
|
454 | 454 | //! ```
|
455 | 455 | //!
|
456 | 456 | //! print two significantly different things:
|
457 |
| -//! |
| 457 | +//! |
458 | 458 | //! ```text
|
459 | 459 | //! Hello, `1234.560` has 3 fractional digits
|
460 | 460 | //! Hello, `123` has 3 characters
|
|
0 commit comments