Complete-Reference-Vb Net 27
Complete-Reference-Vb Net 27
y en US April, 2001
y af ZA April 2001
L en UZ Unrecognized format specifier; a format exception is thrown
Digit or Zero for a Placeholder
The following code formats the output to the designated number of digits using a zero as the placeholder. If
there are more placeholders than digits passed in the argument, the output is left−padded with the placeholder
zeros. For example:
Console.WriteLine("{0:111}", 1234)
Console.WriteLine("{0:00}", 12)
Console.WriteLine("{0:0000}", 123)
Console.WriteLine("{0:0000}", 1234)
111
12
0123
1234
In the preceding output, the first line generates three of digit "1" because this placeholder is not recognized by
the method and is thus simply copied to the output, and the number (1234) as the argument is ignored. The
second line shows output limited to two digits. The third line shows output limited to four digits, but because
we only provide a three−digit String as the argument, the number is left−padded with a zero. The fourth line
shows four numbers formatted to a String of four digits.
The pound (or hash) character can be used as the digit or space placeholder. This placeholder works just like
the zero except that a space or blank is inserted into the output if no digit is used in the specified position. For
example:
Console.WriteLine("{0:####}", 123)
Console.WriteLine("{0:####}", 1234)
Console.WriteLine("{0:##}", 123456)
123
1234
123456
You can determine the position of the decimal point in a String of numerals by specifying the position of the
period (.) character in the format String. You can also customize the character used as a decimal point in the
NumberFormatInfo class. Here is an example:
Console.WriteLine("{0:####.000}", 123456.7)
Console.WriteLine("{0:##.000}", 12345.67)
Console.WriteLine("{0:#.000}", 1.234567)
511