d3.format "none" 类型不四舍五入
d3.format "none" type not rounding
d3 documentation 指出 (none) 格式类型有效 "like g
, but trims insignificant trailing zeros"。 g
格式类型使用 "either decimal or exponent notation, rounded to significant digits."
Mike Bostock explained "The none format type trims trailing zeros, but the precision is interpreted as significant digits rather than the number of digits past the decimal point."
如果我使用 d3.format('.2')(2.0)
,我会得到 2
(尾随零被删除)。
但是当我使用 d3.format('.2')(2.001)
时,结果是 2.001
:没有舍入。我本以为结果是 2.0
(四舍五入到两位有效数字,但保留零),或 2
(四舍五入到两位有效数字,然后去掉零)。
这是一个错误,还是我误解了语法?
发生这种情况是因为我使用的是旧版本的 d3(3.5.17,它随 plot.ly 1.27.1 的当前版本一起提供)。
在该版本的 d3 中,(none) 格式类型 doesn't exist。它于 2015 年推出。
d3 documentation 指出 (none) 格式类型有效 "like g
, but trims insignificant trailing zeros"。 g
格式类型使用 "either decimal or exponent notation, rounded to significant digits."
Mike Bostock explained "The none format type trims trailing zeros, but the precision is interpreted as significant digits rather than the number of digits past the decimal point."
如果我使用 d3.format('.2')(2.0)
,我会得到 2
(尾随零被删除)。
但是当我使用 d3.format('.2')(2.001)
时,结果是 2.001
:没有舍入。我本以为结果是 2.0
(四舍五入到两位有效数字,但保留零),或 2
(四舍五入到两位有效数字,然后去掉零)。
这是一个错误,还是我误解了语法?
发生这种情况是因为我使用的是旧版本的 d3(3.5.17,它随 plot.ly 1.27.1 的当前版本一起提供)。
在该版本的 d3 中,(none) 格式类型 doesn't exist。它于 2015 年推出。