Format Styles

The following table shows the format style options, and demonstrates how these options would change the appearance of a sample input number, 1235.00.

Format Style Usage and Examples
Format Style Values Description Examples
Mask Output
Fill All characters Accepts all characters except curly brackets: { and }    
Align < Forces left-alignment within the specified space. *<6 1235**
> Forces right-alignment within the specified space (default). *>6 **1235
^ Forces central alignment within the specified space. *^6 *1235*
Sign Plus + Uses a sign for both positive and negative numbers. + +1235
Minus - Uses a sign for only negative numbers (default). - -1235
Space Uses a leading space on positive numbers, and a minus sign on negative numbers. ' ' 1235
Symbol $ Prefixes the $ (Dollar) currency symbol. $ $1235
£ Prefixes the £ (Pounds Sterling) currency symbol. £ £1235
¥ Prefixes the ¥ (Japanese Yen) currency symbol. ¥ ¥1235
Prefixes the ₹ (Indian Rupee) currency symbol. ₹1235
Prefixes the € (Euro) currency symbol. €1235
0 0 Enables zero-padding. 06 001235
Width width Defines the minimum field width. If not specified, the width is determined by the content. 6   1235
, , Enables the use of a comma to separate every third digit. , 1,235
Precision .precision Indicates how many digits must be displayed after the decimal point, for a value formatted with types e, f and %, or before and after the decimal point for values formatted with types g, r, and p. See f, g, r, p, and % types for examples
Types b Binary: Outputs the number in base 2. b 10011010011
c Character: Converts the integer to the corresponding Unicode character. c ä
d Integer: Outputs the number in base 10. Ignores non-integer values. d 1235
e Exponent notation: Displays the number in scientific notation, using the letter e to indicate the exponent. e 1.235e+3
.1e 1.2e+3
f Fixed point: Displays the number as a fixed-point number. f 1235
.1f 1235.0
g General: For a given precision p >= 1, this rounds the number to p significant digits and then formats the result in either fixed-point format or in scientific notation, depending on its magnitude. g 1235
.2g 1.2e+3
.5g 1235.0
n Formatted Number: This is the same as d, except that it uses the current locale setting to insert the appropriate number separator characters. n 1,235
.2n 1.2e+3
.5n 1,235.0
o Octal: Outputs the number in base 8. o 2323
r Rounded: Similar to general format, but does not use scientific notation. r 1235
.2r 1200
.5r 1235.0

String: Rounded and using scientific notation, but with a unit suffixed. See Quantity Prefixes, Name and Symbol.

  • Renders micro (0.000001 or 10-6) as 1.00μ.
  • Renders tera (1,000,000,000,000 or 1012) as 1.00T.
s 1.235k
.2s 1.2k
.5s 1.2350k

String: Rounded and using regular currency unit suffixed. See Quantity Prefixes, Word.

  • Renders 1,000,000,000 as 1B, for billions.
  • Renders 1,000,000,000,000 as 1T, for trillions.
$S $1235
$S, $1,235

Hex: Outputs the number in base 16, using the lower-case letters for the digits above 9.

a for 10, b for 11, c for 12, d for 13, e for 14, and f for 15.

x 4d3

Hex: Outputs the number in base 16, using the lower- case letters for the digits above 9.

A for 10, B for 11, C for 12, D for 13, E for 14, and F for 15.

X 4D3
% Percentage: Multiplies the number by 100 and displays it in fixed f format, followed by a percent sign. % 123500%
.1% 123500.0%