Skip to content

Commit 3851cf6

Browse files
authored
Fix incorrect padding in fixed-width print (#1584)
When using fixed-width padded strings, the explanation/example adds an extra padding character. println!("{number:>5}", number=1); formats the string to length 5, but the example text displays a string of width 6. Similarly: println!("{number:0>5}", number=1); pads with four zeroes, but the example shows five zeroes and then a "1" which is incorrect. This commit corrects both of these errors.
1 parent 5aad12e commit 3851cf6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/hello/print.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ fn main() {
3838
println!("Base 16 (hexadecimal) repr: {:X}", 69420);
3939
4040
// You can right-align text with a specified width. This will output
41-
// " 1". 5 white spaces and a "1".
41+
// " 1". 4 white spaces and a "1", for a total width of 5.
4242
println!("{number:>5}", number=1);
4343
44-
// You can pad numbers with extra zeroes. This will output "000001".
44+
// You can pad numbers with extra zeroes. This will output "00001".
4545
println!("{number:0>5}", number=1);
4646
4747
// You can use named arguments in the format specifier by appending a `$`

0 commit comments

Comments
 (0)