Formatting of Numeric Strings

Formatting of Numeric Strings

The general format of a Format String is:

  • “{<argument index>[,<alignment>][:<formatString><zeros>]}”

e.g.:   {0,-8:G2}

argument index: mandatory This represent which argument goes into the string
alignment: optional This represent the minimal length of the string
Postive values, the string argument will be right justified
format string: optional This represent the format code.
C(urrency), D(ecimal), E(xponential), F(ixed), G(eneral), N(umber), P(ercent), X(adecimal)
zeros: optional It actually has a different meaning depending on which numeric specifier you use

A number of examples

“{0:C4}”, 10 $10.0000
“{0:D4}”, 10 0010
“{0:D4}”, -10 -0010
“{0:E4}”, 10 1.0000E+001
“{0:E4}”, -10 -1.0000E+001
“{0:F4}”, 10 10.0000
“{0:F4}”, -10 -10.0000
“{0:G4}”, 10 10
“{0:G4}”, -10 -10
“{0:N4}”, 10 10.0000
“{0:N4}”, -10 -10.0000
“{0:P4}”, 10 1,000.0000%
“{0:P4}”, -10 -1,000.0000%
“{0:X4}”, 10 000A
“{0:X4}”, -10 FFFFFFF6
“{0:4}”, 10 4
“{0:4}”, -10 -4
Advertenties

Reacties zijn gesloten.

%d bloggers liken dit: