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 enable you to easily display commonly used numeric formats. The following table lists the standard numeric specifiers.

C or c 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).
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 one ...

Get Visual Basic 2012 Programmer's Reference now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.