Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

RtReports

Numeric format strings

  • Last UpdatedJan 24, 2023
  • 4 minute read

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.

  • Byte or SByte: 3

  • Int16 or UInt16: 5

  • Int32 or UInt32: 10

  • Int64 or UInt64: 19

  • Single: 7 Double: 15

  • Decimal: 29

    Fixed-point notation is used if the exponent that would result from expressing the number in scientific notation is greater than -5 and less than the precision specifier; otherwise, scientific notation is used. The result contains a decimal point if required and trailing zeroes are omitted. If the precision specifier is present and the number of significant digits in the result exceeds the specified precision, then the excess trailing digits are removed by rounding. If scientific notation is used, the exponent in the result is prefixed with 'E' if the format specifier is 'G', or 'e' if the format specifier is 'g'. The exception to the preceding rule is if the number is a Decimal type and the precision specifier is omitted. In that case, fixed-point notation is always used and trailing zeroes are preserved.

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

Related Links
TitleResults for “How to create a CRG?”Also Available in