Numeric format strings
- Last UpdatedJan 24, 2023
- 4 minute read
- PI System
- RtReports 5.0
- Visualization
Standard numeric format strings control formatting for common numeric types.
A standard format string takes the form Axx, where A is a single alphabetic character called the format specifier, and xx is an optional integer called the precision specifier.
-
The format specifier must be one of the built-in format characters.
-
The precision specifier ranges from 0 to 99 and controls the number of significant digits or zeros to the right of a decimal.
-
The format string cannot contain white spaces.
Note: The result string produced by these format specifiers is influenced by the Region and Language settings on your computer. Computers using different region, language, and advanced number and time settings will generate different result strings.
Standard numeric format string specifiers
|
Format string specifier |
Name |
Description |
|---|---|---|
|
C or c |
Currency |
The number is converted to a string that represents a currency amount. The precision specifier indicates the desired number of decimal places. |
|
D or d |
Decimal |
This format is supported for integral types only. The number is converted to a string of decimal digits (0-9), prefixed by a minus sign if the number is negative. The precision specifier indicates the minimum number of digits desired in the resulting string. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier. |
|
E or e |
Scientific |
The number is converted to a string of the form "-d.ddd...E+ddd" or "-d.ddd...e+ddd", where each 'd' indicates a digit (0-9). The string starts with a minus sign if the number is negative. One digit always precedes the decimal point. The precision specifier indicates the desired number of digits after the decimal point. If the precision specifier is omitted, a default of six digits after the decimal point is used. The case of the format specifier indicates whether to prefix the exponent with an 'E' or an 'e'. The exponent always consists of a plus or minus sign and a minimum of three digits. The exponent is padded with zeros to meet this minimum, if required. |
|
F or f |
Fixed-point |
The number is converted to a string of the form "-ddd.ddd..." where each 'd' indicates a digit (0-9). The string starts with a minus sign if the number is negative. The precision specifier indicates the desired number of decimal places. |
|
G or g |
General |
The number is converted to the most compact of either fixed-point or scientific notation, depending on the type of the number and whether a precision specifier is present. If the precision specifier is omitted or zero, the type of the number determines the default precision, as indicated by the following list.
|
|
N or n |
Number |
The number is converted to a string of the form "-d,ddd,ddd.ddd...", where each 'd' indicates a digit (0-9). The string starts with a minus sign if the number is negative. Thousand separators are inserted between each group of three digits to the left of the decimal point. The precision specifier indicates the desired number of decimal places. |
|
P or p |
Percent |
The number is converted to a string that represents a percent. The precision specifier indicates the desired number of decimal places. |
Examples for standard format specifiers
|
Format string specifier |
Culture or Locale setting |
Data type |
Value |
Report output |
|---|---|---|---|---|
|
C |
en-US |
Double |
12345.6789 |
$12,345.68 |
|
C |
de-DE |
Double |
12345.678 |
12.345,68 DM |
|
D |
en-US |
Int32 |
12345 |
12345 |
|
D8 |
en-US |
Int32 |
12345 |
00012345 |
|
E |
en-US |
Double |
12345.6789 |
1.234568E+004 |
|
E10 |
en-US |
Double |
12345.6789 |
1.2345678900E+004 |
|
E |
fr-FR |
Double |
12345.6789 |
1,234568E+004 |
|
e4 |
en-US |
Double |
12345.6789 |
1.2346e+004 |
|
F |
en-US |
Double |
12345.6789 |
12345.68 |
|
F |
es-ES |
Double |
12345.6789 |
12345,68 |
|
F0 |
en-US |
Double |
12345.6789 |
123456 |
|
F6 |
en-US |
Double |
12345.6789 |
12345.678900 |
|
G |
en-US |
Double |
12345.6789 |
12345.6789 |
|
G7 |
en-US |
Double |
12345.6789 |
12345.68 |
|
G |
en-US |
Double |
0.0000023 |
2.3E-6 |
|
G |
en-US |
Double |
0.0023 |
0.0023 |
|
G2 |
en-US |
Double |
1234 |
1.2E3 |
|
G |
en-US |
Double |
Math.PI |
3.14159265358979 |
|
N |
en-US |
Double |
12345.6789 |
12,345.68 |
|
N |
sv-SE |
Double |
12345.6789 |
12 345,68 |
|
N4 |
en-US |
Double |
123456789 |
123,456,789.0000 |
|
P |
en-US |
Double |
.126 |
12.60 % |
|
r |
en-US |
Double |
Math.PI |
3.141592653589793 |
|
x |
en-US |
Int32 |
0x2c45e |
2c45e |
|
X |
en-US |
Int32 |
0x2c45e |
2C45E |
|
X8 |
en-US |
Int32 |
0x2c45e |
0002C45E |
|
x |
en-US |
Int32 |
123456789 |
75bcd15 |