Skip to content

Commit 3dcdfbf

Browse files
committed
Fix a couple of edge cases.
1 parent a31f592 commit 3dcdfbf

4 files changed

Lines changed: 5 additions & 3 deletions

File tree

d3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@
634634
return x.toFixed(p);
635635
},
636636
r: function(x, p) {
637-
return (x = d3.round(x, d3_format_precision(x, p))).toFixed(Math.max(0, Math.min(20, d3_format_precision(x * (1 + ε), p))));
637+
return (x = d3.round(x, d3_format_precision(x, p))).toFixed(Math.max(0, Math.min(20, d3_format_precision(x * (1 + 1e-15), p))));
638638
}
639639
});
640640
function d3_format_precision(x, p) {

d3.min.js

Lines changed: 1 addition & 1 deletion
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
@@ -95,7 +95,7 @@ var d3_format_types = d3.map({
9595
g: function(x, p) { return x.toPrecision(p); },
9696
e: function(x, p) { return x.toExponential(p); },
9797
f: function(x, p) { return x.toFixed(p); },
98-
r: function(x, p) { return (x = d3.round(x, d3_format_precision(x, p))).toFixed(Math.max(0, Math.min(20, d3_format_precision(x * (1 + ε), p)))); }
98+
r: function(x, p) { return (x = d3.round(x, d3_format_precision(x, p))).toFixed(Math.max(0, Math.min(20, d3_format_precision(x * (1 + 1e-15), p)))); }
9999
});
100100

101101
function d3_format_precision(x, p) {

test/core/format-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ suite.addBatch({
145145
assert.strictEqual(format(".1r")(.09), "0.09");
146146
assert.strictEqual(format(".1r")(.949), "0.9");
147147
assert.strictEqual(format(".1r")(.0949), "0.09");
148+
assert.strictEqual(format(".10r")(.9999999999), "0.9999999999");
149+
assert.strictEqual(format(".15r")(.999999999999999), "0.999999999999999");
148150
},
149151
"can round very small numbers": function(format) {
150152
var f = format(".2r");

0 commit comments

Comments
 (0)