Skip to content

Commit

Permalink
Update print.md (#1597)
Browse files Browse the repository at this point in the history
On the website, there are two options listed for hexadecimal. I was confused what the difference between the capital x and X was but then I ran it through and realized the latter capitalized the letters. I've also done the courtesy of listing out their subsequent results.

I also added some additional information to the "width" section and formatted it for easier readability.
  • Loading branch information
ArikRahman authored Aug 14, 2022
1 parent 3a5ffcb commit 03301f8
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/hello/print.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ fn main() {
// Different formatting can be invoked by specifying the format character after a
// `:`.
println!("Base 10 repr: {}", 69420);
println!("Base 2 (binary) repr: {:b}", 69420);
println!("Base 8 (octal) repr: {:o}", 69420);
println!("Base 16 (hexadecimal) repr: {:x}", 69420);
println!("Base 10: {}", 69420); //69420
println!("Base 2 (binary): {:b}", 69420); //10000111100101100
println!("Base 8 (octal): {:o}", 69420); //207454
println!("Base 16 (hexadecimal): {:x}", 69420); //10f2c
println!("Base 16 (hexadecimal): {:X}", 69420); //10F2C
// You can right-align text with a specified width. This will output
// " 1". 4 white spaces and a "1", for a total width of 5.
// You can right-justify text with a specified width. This will
// output " 1". (Four white spaces and a "1", for a total width of 5.)
println!("{number:>5}", number=1);
// You can pad numbers with extra zeroes. This will output "00001".
println!("{number:0>5}", number=1);
// You can pad numbers with extra zeroes,
//and left-adjust by flipping the sign. This will output "10000".
println!("{number:0<5}", number=1);
// You can use named arguments in the format specifier by appending a `$`
println!("{number:0>width$}", number=1, width=5);
Expand Down

0 comments on commit 03301f8

Please sign in to comment.