Formatting Numbers
Numbers can only be formatted with a single shortcut character such as "G", or a composite of specifiers, such as "##0,000.0". If you attempt to use a shortcut character in a format specifier larger than one character, it will be copied to the output unchanged (treated as a literal character).
Run your production exports with the appropriate culture selected to ensure the output is correctly formatted.
Table 12-5 Single Character Shortcut Numeric Formats
Format | Description |
---|---|
D |
Whole number (with locale-aware negative sign for negative numbers) |
D<precision> |
Whole number formatted to at least <precision> digits, zero-padded if necessary. For example, 123 with "{0:D5}" will output 12300. |
E |
Exponential (scientific) notation "1.234E+10" |
F |
Floating point number "123.456" (with locale-aware decimal separator and negative sign for negative numbers) |
F<precision> |
Floating point number rounded to <precision> significant digits after the decimal |
G |
General number format |
N |
Generalized Numeric format "123,456.789" (with locale-aware group/decimal separators and negative sign for negative numbers) |
N<precision> |
Generalized Numeric rounded to <precision> digits after the decimal |
P |
Percent (for 0.20146 outputs "20.14%" with locale-aware group/decimal separators and negative sign for negative numbers) |
P<precision> |
Percent rounded to <precision> significant digits (for 0.205 "{0:P0" outputs "21%") |
X |
Hexadecimal (base-16) output "4D2" |
Table 12-6 Numeric Format Specifiers
Format | Description |
---|---|
0 |
Zero placeholder, outputs digit if present, otherwise zero |
# |
Digit placeholder, outputs digit if present, otherwise does not produce output |
. |
Locale-specific decimal separator |
, |
When placed between placeholders, outputs a locale-specific group separator (for 123456789 "{0:#,#}" outputs "123,456,789"). When one or more are placed immediately to the left of the decimal point (or implicit decimal point) the number is divided by 1000 for every comma (for 123456789 "{0:#,##0,,}" outputs "1,235"). |
% |
Multiplies the number by 100 and outputs a locale-specific percentage symbol at the given location |
E<sign>0 |
Exponential notation. At least one zero is required, with the number of zeros specifying the minimum digits in the exponent. <sign> is optional and can be:
|
\<char> |
Escape character (<char> is treated as literal output) |
; |
Section separator. If present, allows definition of different formats for positive numbers, negative numbers, and zeros.
|
Any other character |
Copied to output unchanged |