Appendix Q Other Format Specifiers
A program uses format specifiers to determine how objects are represented as strings. C# provides two kinds of specifiers: standard format specifiers and custom format specifiers. Standard format specifiers are locale-aware, so the result depends on the computer’s regional settings. If a program uses standard format specifiers and you run the program in a new locale, it automatically produces the formats appropriate for that locale. For that reason, you should always use the standard specifiers whenever possible.
The following sections describe the standard and custom format specifiers.
Standard Numeric Format Specifiers
Standard numeric format specifiers enable you to easily display commonly used numeric formats. The following table lists the standard numeric specifiers.
Specifier | Meaning |
C or c | Currency. If a precision specifier follows the C , it indicates the number of digits that should follow the decimal point. On a standard system in the United States, the value –1234.5678 with the specifier C3 produces ($1,234.568). |
D or d | Decimal. This specifier works only with integer types. It simply displays the number’s digits. If a precision specifier follows the D , it indicates the number of digits the result should have, padding on the left with zeros, if necessary. If the value is negative, the result has a minus sign on the left. The value –1234 with the specifier D6 produces –001234. |
E or e | Scientific notation. The result always has exactly ... |
Get C# 5.0 Programmer's Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.