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 value | shortcut | description |
---|---|---|
exponent | e | uses Number.toExponential |
general | g | uses Number.toPrecision |
fixed | f | uses Number.toFixed |
integer | d | uses Number.toString |
rounded | r | rounds 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 percentage | p | see percentage (%), but rounds to [.precision] |
binary | b | displays the number in base 8 |
hexadecimal | x | displays the number in base 16, using lower-case letters for the digits above 9 |
hexadecimal | X | displays the number in base 16, using upper-case letters for the digits above 9 |
character | c | converts the integer to the corresponding unicode character before printing |
SI prefix | s | see 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:
align | description |
---|---|
< | aligned left |
> | aligned right |
^ | central alignment |
By default, > (aligned right) is selected.
The prefix can be:
prefix | description |
---|---|
+ | this sign can be used for both positive and negative numbers |
- | this sign can be used for both positive and negative numbers |
space | a leading space (" ") should be used on positive numbers and a minus sign on negative numbers |
The symbol can be:
shortcut | description |
---|---|
$ | adds the currency sign |
# | for binary, octal, or hexadecimal output, prefix |
0 | enables 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".