1. [ C++ ] Printing an integer
test text
1. [ Java ] Printing an integer
The printf method takes a format string as the first parameter. This string is printed but following parameters replace the % placeholders.
%d is used for decimal numbers.
| Format | Code | Meaning |
| Simple | %d | A simple decimal number |
| Right aligned | %5d | Print right aligned in 5 characters. Fill any unused characters with spaces. |
| Leading zeroes | %05d | Print right aligned in 5 characters. Fill any unused characters with zero. |
| Hexadecimal | %x | Print as a hexadecimal (base 16) number. |
| With commas | %,d | Use , to separate thousands. |
test text
1. [ C# ] Printing an integer
The Write method takes a format string as the first parameter.
This string is printed but following parameters replace the {} placeholders.
| Format | Code | Meaning |
| Simple | {0} |
Simple conversion to string |
| Right aligned | {0,12} |
Print right aligned in 12 characters. Fill any unused characters with spaces. |
| Leading zeroes | {0:00000} |
Print right aligned in 5 characters. Fill any unused characters with zero. |
| Hexadecimal | %x |
Print as a hexadecimal (base 16) number. |
| With commas | {0,12:n0} |
Use , to separate thousands
The whole string takes 12 characters, :n0 means number format with 0 decimal places.
|
test text
1. [ Perl ] Printing an integer
The printf method takes a format string as the first parameter. This string is printed but following parameters replace the % placeholders.
%d is used for decimal numbers.
| Format | Code | Meaning |
| Simple | %d | A simple decimal number |
| Right aligned | %5d | Print right aligned in 5 characters. Fill any unused characters with spaces. |
| Leading zeroes | %05d | Print right aligned in 5 characters. Fill any unused characters with zero. |
| Hexadecimal | %x | Print as a hexadecimal (base 16) number. |
| With commas | %,d | Use , to separate thousands. |
test text