tickFormat
This attribute can change a numerical tick value to a formatted number by the given string specifier. The general form of a specifier is:
[[fill]align][sign][symbol][0][width][,][.precision][~][type]
The fill
can be any character. The presence of a fill character is signaled by the align character following it, which must be one of the following:
>
- Forces the field to be right-aligned within the available space. (Default behavior).<
- Forces the field to be left-aligned within the available space.^
- Forces the field to be centered within the available space.=
- like>
, but with any sign and symbol to the left of any padding.
Thesign
can be:
-
- nothing for zero or positive and a minus sign for negative. (Default behavior.)+
- a plus sign for zero or positive and a minus sign for negative.(
- nothing for zero or positive and parentheses for negative.
The symbol
can be:
$
- apply currency symbols per the locale definition.#
- for binary, octal, or hexadecimal notation, prefix by0b
,0o
, or0x
, respectively.
The zero (0
) option enables zero-padding; this implicitly sets fill to 0
and align to =
. 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 group separator, such as a comma for thousands.
Depending on the type, the precision either indicates the number of digits that follow the decimal point (types f
and %
), or the number of significant digits (types `,
e,
g,
r,
sand
p). If the precision is not specified, it defaults to 6 for all types except
(none), which defaults to 12. Precision is ignored for integer formats (types
b,
o,
d,
x, and
X) and character data (type
c`). See precisionFixed and precisionRound for help picking an appropriate precision.
The ~
option trims insignificant trailing zeros across all format types. This is most commonly used in conjunction with types r
, e
, s
and %
. For example:
String specifier | Original Number | Formatted Number |
---|---|---|
s | 1500 | 1.50000k |
~s | 1500 | 1.5k |
The available type
values are:
e
- exponent notation(eg.1.23e+2
).E
- exponent notation(eg.1.23 x 10²
).f
- fixed point notation.g
- either decimal or exponent notation, rounded to significant digits.r
- decimal notation, rounded to significant digits.s
- decimal notation with an SI prefix, rounded to significant digits.%
- multiply by 100, and then decimal notation with a percent sign.p
- multiply by 100, round to significant digits, and then decimal notation with a percent sign.b
- binary notation, rounded to integer.o
- octal notation, rounded to integer.d
- decimal notation, rounded to integer.x
- hexadecimal notation, using lower-case letters, rounded to integer.X
- hexadecimal notation, using upper-case letters, rounded to integer.c
- character data, for a string of text.
The type ` (none) is also supported as shorthand for
~g(with a default precision of 12 instead of 6), and the type
nis shorthand for
,g. For the
g,
nand
` (none) types, decimal notation is used if the resulting string would have precision or fewer digits; otherwise, exponent notation is used. For example:
String specifier | Original Number | Formatted Number |
---|---|---|
.2 | 42 | 42 |
.2 | 4.2 | 4.2 |
.1 | 42 | 4e+1 |
.1 | 4.2 | 4 |
Examples
e
- exponent notation.
String specifier | Original Number | Formatted Number |
---|---|---|
.1e | 0.123 | 1.2e-1 |
.2e | 0.123 | 1.23e-1 |
.1e | 123 | 1.2e+1 |
.2e | 123 | 1.23e+2 |
E
- exponent notation.
String specifier | Original Number | Formatted Number |
---|---|---|
.1E | 0.123 | 1.2 x 10⁻¹ |
.2E | 0.123 | 1.23 x 10⁻¹ |
.1E | 123 | 1.2 x 10² |
.2E | 123 | 1.23 x 10² |
f
- fixed point notation.
String specifier | Original Number | Formatted Number |
---|---|---|
.0f | 1.126 | 1 |
.1f | 1.126 | 1.1 |
.2f | 1.126 | 1.13 |
.3f | 1.126 | 1.126 |
,.5f | 100000000.126 | 100,000,000.12600 |
g
- either decimal or exponent notation, rounded to significant digits.
String specifier | Original Number | Formatted Number |
---|---|---|
.0g | 1.126 | 1 |
.1g | 1.126 | 1 |
.2g | 1.126 | 1.1 |
.3g | 1.126 | 1.13 |
.4g | 1.126 | 1.126 |
.4g | 0.000000126 | 1.260e-7 |
.4g | 126000000 | 1.260e+8 |
r
- decimal notation, rounded to significant digits.
String specifier | Original Number | Formatted Number |
---|---|---|
.2r | 4223 | 4200 |
,.2r | 4223 | 4,200 |
,.3r | 4223 | 4,220 |
s
- decimal notation with an SI prefix, rounded to significant digits.y
- yocto, 10⁻²⁴z
- zepto, 10⁻²¹a
- atto, 10⁻¹⁸f
- femto, 10⁻¹⁵p
- pico, 10⁻¹²n
- nano, 10⁻⁹µ
- micro, 10⁻⁶m
- milli, 10⁻³k
- kilo, 10³M
- mega, 10⁶G
- giga, 10⁹T
- tera, 10¹²P
- peta, 10¹⁵E
- exa, 10¹⁸Z
- zetta, 10²¹Y
- yotta, 10²⁴
String specifier | Original Number | Formatted Number |
---|---|---|
.2s | 42000000 | 42M |
.2s | 0.0042 | 4.2m |
.2s | 0.0000042 | 4.2µ |
s | 1500 | 1.50000k |
~s | 1500 | 1.5k |
%
- multiply by 100, and then decimal notation with a percent sign.
String specifier | Original Number | Formatted Number |
---|---|---|
.0% | 0.123 | 12% |
.1% | 0.123 | 12.3% |
tickValues
This attribute is used to set specific tick values according to a given string specifier, containing numerical tick values separated by comma.