Merge branch 'fix-format-zero-sigfig' into release
This commit is contained in:
Коммит
fd0759f02a
|
@ -530,7 +530,7 @@ var d3_format_types = {
|
||||||
e: function(x, p) { return x.toExponential(p); },
|
e: function(x, p) { return x.toExponential(p); },
|
||||||
f: function(x, p) { return x.toFixed(p); },
|
f: function(x, p) { return x.toFixed(p); },
|
||||||
r: function(x, p) {
|
r: function(x, p) {
|
||||||
var n = 1 + Math.floor(1e-15 + Math.log(x) / Math.LN10);
|
var n = x ? 1 + Math.floor(1e-15 + Math.log(x) / Math.LN10) : 1;
|
||||||
return d3.round(x, p - n).toFixed(Math.max(0, Math.min(20, p - n)));
|
return d3.round(x, p - n).toFixed(Math.max(0, Math.min(20, p - n)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -66,7 +66,7 @@ var d3_format_types = {
|
||||||
e: function(x, p) { return x.toExponential(p); },
|
e: function(x, p) { return x.toExponential(p); },
|
||||||
f: function(x, p) { return x.toFixed(p); },
|
f: function(x, p) { return x.toFixed(p); },
|
||||||
r: function(x, p) {
|
r: function(x, p) {
|
||||||
var n = 1 + Math.floor(1e-15 + Math.log(x) / Math.LN10);
|
var n = x ? 1 + Math.floor(1e-15 + Math.log(x) / Math.LN10) : 1;
|
||||||
return d3.round(x, p - n).toFixed(Math.max(0, Math.min(20, p - n)));
|
return d3.round(x, p - n).toFixed(Math.max(0, Math.min(20, p - n)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -92,6 +92,7 @@ suite.addBatch({
|
||||||
assert.strictEqual(f(-1.23), "−120%");
|
assert.strictEqual(f(-1.23), "−120%");
|
||||||
},
|
},
|
||||||
"can round to significant digits": function(format) {
|
"can round to significant digits": function(format) {
|
||||||
|
assert.strictEqual(format(".2r")(0), "0.0");
|
||||||
assert.strictEqual(format(".1r")(0.049), "0.05");
|
assert.strictEqual(format(".1r")(0.049), "0.05");
|
||||||
assert.strictEqual(format(".1r")(0.49), "0.5");
|
assert.strictEqual(format(".1r")(0.49), "0.5");
|
||||||
assert.strictEqual(format(".2r")(0.449), "0.45");
|
assert.strictEqual(format(".2r")(0.449), "0.45");
|
||||||
|
|
Загрузка…
Ссылка в новой задаче