Number formatting uses the d3 number format.

You can use the following rules in your formula.

The format specifier is modeled after Python 3.1's built-in format specification mini-language. The general form of a specifier is:

 

[fill][align][sign][symbol][width][,][.precision][type]

The available type values are:

type valueshortcutdescription
exponenteuses Number.toExponential
generalguses Number.toPrecision
fixedfuses Number.toFixed
integerduses Number.toString
roundedrrounds to [.precision] significant digits, padding with zeroes where necessary in similar fashion to fixed (f). If no precision is specified, it falls back to the general notation.
percentage%see fixed (f), but multiplies the value by 100 and adds a % suffix
rounded percentagepsee percentage (%), but rounds to [.precision]
binarybdisplays the number in base 8
hexadecimalxdisplays the number in base 16, using lower-case letters for the digits above 9
hexadecimalXdisplays the number in base 16, using upper-case letters for the digits above 9
charactercconverts the integer to the corresponding unicode character before printing
SI prefixssee rounded (r), but with an additional unit suffix (for example "9.5M" or "1.00µ")

 

The type n is also supported as shorthand for g.

The [fill] can be any character other than "{" or "}". The presence of a [fill] character is signaled by the character following it, which must be one of the align options.

 

The align can be:

aligndescription
<aligned left
>aligned right
^central alignment

By default, > (aligned right) is selected.

 

The prefix can be:

 

 

prefixdescription
+this sign can be used for both positive and negative numbers
-this sign can be used for both positive and negative numbers
spacea leading space (" ") should be used on positive numbers and a minus sign on negative numbers

 

The symbol can be:

shortcutdescription
$adds the currency sign
#for binary, octal, or hexadecimal output, prefix
0enables zero-padding

 

The width defines the minimum field width. If not specified, then the width will be determined by the content.

The comma (,) option enables the use of a comma for a thousands seperator.

The precision indicates the number of digits to be displayed after the decimal point for a value formatte dwith types "f" and "%", or before and after the decimal point for a value formatted with types "g", "r", and "p".

  • No labels