d3-format icon indicating copy to clipboard operation
d3-format copied to clipboard

Unit is generated outside parenthesis for negative numbers

Open GlenKelley opened this issue 3 years ago • 0 comments

When using the Accounting number format which uses parentheses for negative numbers, and also using units, the units will be placed outside the parenthesis which is atypical and is not consistent with the behaviour between format and formatPrefix.

For example, this appears broken:

formatPrefix("(~s", 1e3)(-1e3) will produce (1)k, instead of (1k).

But this works as intended:

format("(~s")(-1e3) will produce (1k)

The above example is the simplest reproduction of the error, but there are cases where formatPrefix is required. For example:

formatPrefix("($,.6~f", 1e6)(-1e3) will produce ($0.1)M instead of ($0.1M)

GlenKelley avatar Jan 19 '23 22:01 GlenKelley