Number Format Masks


.NET Number and Currency Format Masks

Standard Format Masks

Standard format masks are single-character specifiers that apply common numeric formatting. The output varies based on the system's culture settings.

Character Description Example (en-US)
c / C Currency format $20.99
d / D Decimal format (integers only) 2099
e / E Scientific (exponential) format 2.099000e+003
f / F Fixed-point format 20.99
g / G General format 20.99
n / N Number format (with group separators) 20.99
p / P Percent format 2,099.00%

Note: These formats are affected by the current culture (e.g., decimal and group separators).

Custom Format Masks

Custom numeric format strings allow you to define precise formatting rules using a combination of symbols.

Syntax Structure:

<sign><integral-digits>.<fractional-digits>

Components:

Component Description
<sign> Optional + or - to indicate positive or negative values
<integral-digits> Digits to the left of the decimal point
. Culture-specific decimal separator
<fractional-digits> Digits to the right of the decimal point

Example:

To display a number with 4 decimal places and a leading sign, use:

+9999.0000

This would format:

  • 20.5 as +0020.5000
  • -3.1 as -0003.1000