HomeGuidesRecipesAPI
HomeGuidesAPILog In
Guides
These docs are for v16. Click to read the latest docs for v31.

Custom numeric format strings

You can create a custom numeric format string, which consists of one or more custom numeric specifiers, to define how to format numeric data. A custom numeric format string is any format string that is not a standard numeric format string.

The following table describes the custom numeric format specifiers and displays sample output produced by each format specifier.

🚧

Note:

Commas, decimal points, percent symbols and zeros are all specific format specifiers. Using these symbols in combination with the # digit placeholder to create format patterns may cause in unexpected results. If any of these symbols are used as character literals rather than format specifiers they must be escaped with the \ escape character. See below for more information.

This information is a summary of the Custom numeric format strings page from Microsoft and includes links to more information on each Format string from that page.

See the Notes section for additional information about using custom numeric format strings, and the Example section for a comprehensive illustration of their use.

Format StringNameDescriptionExamples
0Zero placeholderReplaces the zero with the corresponding digit if one is present; otherwise, zero appears in the result string.

More information: The "0" Custom Specifier.
1234.5678 ("00000") -> 01235

Culture: en-US
0.45678 ("0.00") -> 0.46

Culture: fr-FR
0.45678 ("0.00") -> 0,46
#Digit placeholderReplaces the "#" symbol with the corresponding digit if one is present; otherwise, no digit appears in the result string.

Note that no digit appears in the result string if the corresponding digit in the input string is a non-significant 0. For example, 0003 ("####") -> 3.

More information: The "#" Custom Specifier.
1234.5678 ("#####") -> 1235

Culture: en-US
0.45678 ("#.##") -> .46

Culture: fr-FR
0.45678 ("#.##") -> ,46
.Decimal pointDetermines the location of the decimal separator in the result string.

More information: The "." Custom Specifier.
Culture: en-US
0.45678 ("0.00") -> 0.46

Culture: fr-FR
0.45678 ("0.00"FR) -> 0,46
,Group separator and number scalingServes as both a group separator and a number scaling specifier. As a group separator, it inserts a localized group separator character between each group. As a number scaling specifier, it divides a number by 1000 for each comma specified.

More information: The "," Custom Specifier.
Group separator specifier:

Culture: en-US
2147483647 ("##,#") -> 2,147,483,647

Culture: es-ES
2147483647 ("##,#") -> 2.147.483.647

Scaling specifier:

Culture: en-US
2147483647 ("#,#,,") -> 2,147

Culture: es-ES
2147483647 ("#,#,,") -> 2.147
%Percentage placeholderMultiplies a number by 100 and inserts a localized percentage symbol in the result string.

More information: The "%" Custom Specifier.
Culture: en-US
0.3697 ("%#0.00") -> %36.97

Culture: el-GR)
0.3697 ("%#0.00") -> %36,97

Culture: en-US
0.3697 ("##.0 %") -> 37.0 %

Culture: el-GR)
0.3697 ("##.0 %") -> 37,0 %
Per mille placeholderMultiplies a number by 1000 and inserts a localized per mille symbol in the result string.

More information: The "‰" Custom Specifier.
Culture: en-US
0.03697 ("#0.00‰") -> 36.97‰

Culture: ru-RU
0.03697 ("#0.00‰") -> 36,97‰
E0

E+0

E-0

e0

e+0

e-0
Exponential notationIf followed by at least one 0 (zero), formats the result using exponential notation. The case of "E" or "e" indicates the case of the exponent symbol in the result string. The number of zeros following the "E" or "e" character determines the minimum number of digits in the exponent. A plus sign (+) indicates that a sign character always precedes the exponent. A minus sign (-) indicates that a sign character precedes only negative exponents.

More information: The "E" and "e" Custom Specifiers.
987654 ("#0.0e0") -> 98.8e4

1503.92311 ("0.0##e+00") -> 1.504e+03

1.8901385E-16 ("0.0e+00") -> 1.9e-16
\Escape characterCauses the next character to be interpreted as a literal rather than as a custom format specifier.

More information: The "" Escape Character.
987654 ("###00#") -> #987654#
'string'

"string"
Literal string delimiterIndicates that the enclosed characters should be copied to the result string unchanged.

More information: Character literals.
68 ("# 'degrees'") -> 68 degrees

68 ("#' degrees'") -> 68 degrees
;Section separatorDefines sections with separate format strings for positive, negative, and zero numbers.

More information: The ";" Section Separator.
12.345 ("#0.0#;(#0.0#);-\0-") -> 12.35

0 ("#0.0#;(#0.0#);-\0-") -> -0-

-12.345 ("#0.0#;(#0.0#);-\0-") -> (12.35)

12.345 ("#0.0#;(#0.0#)") -> 12.35

0 ("#0.0#;(#0.0#)") -> 0.0

-12.345 ("#0.0#;(#0.0#)") -> (12.35)
OtherAll other charactersThe character is copied to the result string unchanged.

More information: Character literals.
68 ("# °") -> 68 °