d3/d3-interpolate

Interpolating strings can drop relevant zeros

boygirl opened this issue · 1 comments

When strings are formatted like: "123, 456, 078" they are can end up dropping the leading zero in the capture group resulting in an incorrect interpolation to: "123,456,78"

This is the expected behavior of d3.interpolateString. Numbers are formatted using the default JavaScript number.toString, which does not use leading zeroes (except for a case like 0.123).

From the referenced issue, it seems like you want comma-formatted numbers such as “1,234,567” to be treated a single number. But d3.interpolateString considers that input as three numbers separated by commas; d3.interpolateString uses the JavaScript number format, and comma-separated thousands are not supported.

You’ll probably want to use a custom interpolator if you want to interpolate comma-separated thousands or other localized number formats.