NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
npm · #560 most downloaded on npm
Format numbers for human consumption.
Last release 8 months ago
14 Jan 2026
Ships unpredictably
gaps range from 3 weeks to 4.1 years
Most releases are documented
notes for 29 of 40 stable releases
Nothing withdrawn
no release was ever pulled
13 years old
43 releases · first in 2014
Avoid use of optional chaining to retain ES2019 compatibility. #149
Fix handling of parens with formatPrefix . #134 #135 #142 Thanks, @GlenKelley !
formatPrefix. #134 #135 #142 Thanks, @GlenKelley!precisionFixed, precisionRound, and precisionPrefix to return NaN when step is zero. #147s format to not sometimes apply an erroneous suffix to NaN or ±Infinity. #147r format now formats zero as 0 instead of 0.0. #147One column per quarter.
Fix documentation for the type c character data format. #116
Update dependencies. Make build reproducible.
This package now requires Node.js 12 or higher. For more, please read Sindre Sorhus’s FAQ .
This package now requires Node.js 12 or higher. For more, please read Sindre Sorhus’s FAQ.
Nothing published for this version
Nothing published for this version
Change the default minus sign to the minus sign (−) instead of hyphen-minus (-). #62
This release adopts ES2015 language features such as for-of and drops support for older browsers, including IE. If you need to support pre-ES2015 environments, you should stick with d3-format 1.x or use a transpiler.
Nothing published for this version
Fix decimal d formatting of numbers greater than or equal to 1e21. #24
d formatting of numbers greater than or equal to 1e21. #24Fix sign of near-zero negative values when using the + sign directive. #92
+ sign directive. #92Fix trimming of trailing zeroes in exponents. #83
Add sideEffects: false to the package.json.
Include locale files when publishing.
Allow minus sign to be localized. Thanks, @benib! #76
Nothing published for this version
Nothing published for this version
Add ~ option to trim insignificant zeros. Thanks, @vasturiano!
~ option to trim insignificant zeros. Thanks, @vasturiano! (#54)Fix relative order of the currency suffix and SI prefix (#53).
Fix thousands separator in fr-FR locale. (#50) Thanks, @victornoel!
Locales can now override the percent sign suffix. Thanks, @davinov!
Nothing published for this version
Locales can now define numeral systems, such as Hindu–Arabic. Thanks, @Ashamandi!
Add module entry point to package.json.
module entry point to package.json.Nothing published for this version
Locale JSON files are now ASCII-encoded.
If a precision is not specified, the formatting behavior has changed: there is now a default precision of 6 for all directives except none, which defaults to 12. In 3.x, if you did not specify a precision, the number was formatted using its shortest unique representation (per number.toString); this could lead to unexpected digits due to floating point math. The new default precision in 4.0 produces more consistent results:
var f = d3.format("e");
f(42); // "4.200000e+1"
f(0.1 + 0.2); // "3.000000e-1"
To trim insignificant trailing zeroes, use the none directive, which is similar g. For example:
var f = d3.format(".3");
f(0.12345); // "0.123"
f(0.10000); // "0.1"
f(0.1 + 0.2); // "0.3"
Under the hood, number formatting has improved accuracy with very large and very small numbers by using number.toExponential rather than Math.log to extract the mantissa and exponent. Negative zero (-0, an IEEE 754 construct) and very small numbers that round to zero are now formatted as unsigned zero. The inherently unsafe d3.round method has been removed, along with d3.requote.
The d3.formatPrefix method has been changed. Rather than returning an SI-prefix string, it returns an SI-prefix format function for a given specifier and reference value. For example, to format thousands:
var f = d3.formatPrefix(",.0", 1e3);
f(1e3); // "1k"
f(1e4); // "10k"
f(1e5); // "100k"
f(1e6); // "1,000k"
Unlike the s format directive, d3.formatPrefix always employs the same SI-prefix, producing consistent results:
var f = d3.format(".0s");
f(1e3); // "1k"
f(1e4); // "10k"
f(1e5); // "100k"
f(1e6); // "1M"
The new ( sign option uses parentheses for negative values. This is particularly useful in conjunction with $. For example:
d3.format("+.0f")(-42); // "-42"
d3.format("(.0f")(-42); // "(42)"
d3.format("+$.0f")(-42); // "-$42"
d3.format("($.0f")(-42); // "($42)"
The new = align option places any sign and symbol to the left of any padding:
d3.format(">6d")(-42); // " -42"
d3.format("=6d")(-42); // "- 42"
d3.format(">(6d")(-42); // " (42)"
d3.format("=(6d")(-42); // "( 42)"
The b, o, d and x directives now round to the nearest integer, rather than returning the empty string for non-integers:
d3.format("b")(41.9); // "101010"
d3.format("o")(41.9); // "52"
d3.format("d")(41.9); // "42"
d3.format("x")(41.9); // "2a"
The c directive is now for character data (i.e., literal strings), not for character codes. The is useful if you just want to apply padding and alignment and don’t care about formatting numbers. For example, the infamous left-pad (as well as center- and right-pad!) can be conveniently implemented as:
d3.format(">10c")("foo"); // " foo"
d3.format("^10c")("foo"); // " foo "
d3.format("<10c")("foo"); // "foo "
There are several new methods for computing suggested decimal precisions; these are used by d3-scale for tick formatting, and are helpful for implementing custom number formats: d3.precisionFixed, d3.precisionPrefix and d3.precisionRound. There’s also a new d3.formatSpecifier method for parsing, validating and debugging format specifiers; it’s also good for deriving related format specifiers, such as when you want to substitute the precision automatically.
You can now set the default locale using d3.formatDefaultLocale! The locales are published as JSON to NPM.
See CHANGES for all D3 changes since 3.x.
Export to the global d3 in vanilla environments (d3/d3#2840).
d3 in vanilla environments (d3/d3#2840).Nothing published for this version
Prefix exported symbols with “format”.
Fix off-by-one in precisionRound.
Nothing published for this version
Expose locales as symbols, not strings (#15).
Defined d3-format module (and d3_format global), not format.
d3-format module (and d3_format global), not format.Fix formatting of negative zero (#14).
Adjust the package.json definition for npm users.
Nothing published for this version
Fix decimal separator in ja-JP locale.
Nothing published for this version
localeFormat now accepts the name of a built-in locale, such as "en-US".
"en-US".Fix for IE11 crash in number.toExponential(undefined).
Nothing published for this version
Nothing published for this version
Nothing published for this version
Your coding agent can read these notes before it upgrades. Set up the MCP server →