Zoo tutorials: [ SQL | Linux | XML ]
ProgZoo: [ Java | C# | VB | C++ | Perl ]
Log in

A Gentle Introduction to
C# Programming

Formatting Integers

 

Input and Output

Formatting Integers

1. [ C# ] Printing an integer


Big

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.