O'Reilly logo

Visual Basic® 2010 Programmer's Reference by Rod Stephens

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

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 digit to the left of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required