You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know there is the possibility to add the currency suffix, but it would be useful to be able to add a more flexible suffix. For example "°C" for temperature values or "kg".
This was secretly added in #135. You can now pass an options second argument to d3.format that accepts a suffix (and prefix). For example:
d3.format("d",{suffix: "°C"})(25)// "25°C"
The advantage of this approach over the above wrappers is that it works correctly with respect to some of the more advanced formatting directives, such as parentheses for negative numbers.
Activity
mbostock commentedon Aug 5, 2021
For a fixed suffix, the recommended way is to wrap the format function. For example:
You can also combine the two like so:
We could perhaps formalize this pattern as:
Or maybe make the arguments order-dependent to allow pre- (e.g., multiplying by 100) and post-formatting:
mbostock commentedon Jan 14, 2026
This was secretly added in #135. You can now pass an
optionssecond argument tod3.formatthat accepts asuffix(andprefix). For example:The advantage of this approach over the above wrappers is that it works correctly with respect to some of the more advanced formatting directives, such as parentheses for negative numbers.