Number Formats
The following are examples that show the output of formatting 1,234.125678. Note for the set of examples below, we use a double value unless otherwise stated.
For more detail, visit the API documentation at Microsoft Learn.
Standard Formatting Methods
| Format String | Result |
|---|---|
| value.ToString() | 1234.125678 |
Predefined Formats
| Format String | Result |
|---|---|
| c -or- C | ¤1,234.13 |
| d -or- D (int only) | 1234 |
| d2 -or- D2 (int only) | 1234 |
| d6 -or- D6 (int only) | 001234 |
| e | 1.234126e+003 |
| e2 | 1.23e+003 |
| e6 | 1.234126e+003 |
| E | 1.234126E+003 |
| E2 | 1.23E+003 |
| E6 | 1.234126E+003 |
| f -or- F | 1234.13 |
| f2 -or- F2 | 1234.13 |
| f6 -or- F6 | 1234.125678 |
| g -or- G | 1234.125678 |
| n -or- N | 1,234.13 |
| n2 -or- N2 | 1,234.13 |
| n6 -or- N6 | 1,234.125678 |
| p -or- P | 123,412.57 % |
| p2 -or- P2 | 123,412.57 % |
| p6 -or- P6 | 123,412.567800 % |
| r -or- R | 1234.125678 |
| x (int only) | 4d2 |
| x2 (int only) | 4d2 |
| x6 (int only) | 0004d2 |
| X (int only) | 4D2 |
| X2 (int only) | 4D2 |
| X6 (int only) | 0004D2 |
Custom Format Strings
| Format String | Result |
|---|---|
| 0.00 | 1234.13 |
| #.00 | 1234.13 |
| #,###.## | 1,234.13 |
| 0,000,000.00 | 0,001,234.13 |
| #,###,###.00 | 1,234.13 |
| (#,###.##) | (1,234.13) |
| 0.00% | 123412.57% |
| #.##;(#.##);-- | 1234.13 |