Skip to content

Commit fd0759f

Browse files
committed
Merge branch 'fix-format-zero-sigfig' into release
2 parents 4c179d9 + dbd7383 commit fd0759f

4 files changed

Lines changed: 5 additions & 4 deletions

File tree

d3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ var d3_format_types = {
530530
e: function(x, p) { return x.toExponential(p); },
531531
f: function(x, p) { return x.toFixed(p); },
532532
r: function(x, p) {
533-
var n = 1 + Math.floor(1e-15 + Math.log(x) / Math.LN10);
533+
var n = x ? 1 + Math.floor(1e-15 + Math.log(x) / Math.LN10) : 1;
534534
return d3.round(x, p - n).toFixed(Math.max(0, Math.min(20, p - n)));
535535
}
536536
};

d3.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/format.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var d3_format_types = {
6666
e: function(x, p) { return x.toExponential(p); },
6767
f: function(x, p) { return x.toFixed(p); },
6868
r: function(x, p) {
69-
var n = 1 + Math.floor(1e-15 + Math.log(x) / Math.LN10);
69+
var n = x ? 1 + Math.floor(1e-15 + Math.log(x) / Math.LN10) : 1;
7070
return d3.round(x, p - n).toFixed(Math.max(0, Math.min(20, p - n)));
7171
}
7272
};

test/core/format-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ suite.addBatch({
9292
assert.strictEqual(f(-1.23), "−120%");
9393
},
9494
"can round to significant digits": function(format) {
95+
assert.strictEqual(format(".2r")(0), "0.0");
9596
assert.strictEqual(format(".1r")(0.049), "0.05");
9697
assert.strictEqual(format(".1r")(0.49), "0.5");
9798
assert.strictEqual(format(".2r")(0.449), "0.45");

0 commit comments

Comments
 (0)