Numeric Values

Format expressions for numbers have up to four sections separated by semicolons (;). The number of sections determines which types of values are affected.

The following table describes how to construct a format string for numeric values:

Format String Character

Description

# (number sign)

Digit placeholder.

The # placeholder displays only significant digits and does not display insignificant zeros. In the decimal value .90, the 0 is considered insignificant. The value would be displayed as .9 when the # placeholder is used.

If a number has more digits to the right of the decimal point than there are placeholders in the format string, the number rounds to as many decimal places as there are placeholders. If there are more digits to the left of the decimal point than there are placeholders, the extra digits are displayed.

 

The following examples illustrate the use of the # placeholder.

Example

Value: 123.896

Format String: #.##

Displays: 123.9

Example

Value: 456.873

Format String: #.##

Displays: 456.87

Example

Value: 34.5678

Format String: #.###

Displays: 34.568

You can combine the # and 0 placeholders in a format string.

0 (zero)

Digit placeholder.

The 0 placeholder displays insignificant zeros if a number has fewer digits than there are zeros in the format string.

If a number has more digits to the right of the decimal point than there are placeholders in the format string, the number rounds to as many decimal places as there are placeholders. If there are more digits to the left of the decimal point than there are placeholders, the extra digits are displayed.

The following examples illustrate the use of the 0 placeholder.

Example

Value: 23.896

Format String: 0.00

Displays: 23.90

Example

Value: 16.8

Format String: 0.000

Displays: 16.800

Example

Value: 7.12

Format String: 000.0

Displays: 007.1

You can combine the # and 0 placeholders in a format string.

E- E+

e- e+

Scientific format.

If the format string contains at least one digit placeholder (0 or #) to the right of E-, E+, e-, e+, the number displays in scientific format and E or e is placed between the number and its exponent.

The number of digit placeholders to the right determines the number of digits in the exponent. Use E- or e- to place a minus sign next to negative exponents. Use E+ or e+ to place a minus sign next to negative exponents and a plus sign next to positive exponents.

- + $ ()

Displays a literal character. To display a character other than one of those listed, precede it with a backslash (\) or enclose it in double quotation marks. (" ").

Numeric Value: -1000.00

Format String: ($-#.##)

Displays: ($-1000.00)

\

Displays the next character in the format string.

Numeric Value: 100

Format String: \t\o\t\a\l\=#

Displays: total=100

The following character cannot be displayed as literals: a, c, d, h, m, n, p, q, s, t, w, y, /, :, #, 0, %, E, e, comma(,), period(.), @, &, <, >, and !

"ABC"

Displays the string inside the double quotes. (In this example, ABC would display.)

Numeric Value: 100

Format String: #" units"

Displays: 100 units