Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update print.md #1597

Merged
merged 1 commit into from
Aug 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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