Appendix Q. Other Format Specifiers
A program uses format specifiers to determine how objects are represented as strings. For example, by using different format specifiers, you can make an integer's ToString method return a value as −12345, −12,345, (12,345), or 012,345−.
Visual Basic provides standard format specifiers in addition to custom specifiers. The standard specifiers make it easy to display values in often-used formats (such as currency or scientific notation). Custom specifiers provide more control over how results are composed.
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 |
|---|---|
| Currency. The exact format depends on the computer's internationalization settings. 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 C produces ($1,234.57). |
| 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. |
| Scientific notation. The result always has exactly one digit to the left of ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access