Permalink
Browse files

Merge branch 'fix-si-format-rounding' into 2.9.2

  • Loading branch information...
mbostock committed May 16, 2012
2 parents 7827bdc + 00bc3f0 commit 5fff2c373d5a38d440dbfea5179276e9cabf11dc
Showing with 11 additions and 10 deletions.
  1. +3 −3 d3.v2.js
  2. +4 −4 d3.v2.min.js
  3. +1 −1 src/core/format.js
  4. +2 −2 src/core/formatPrefix.js
  5. +1 −0 test/core/format-test.js
View
@@ -661,7 +661,7 @@ d3.format = function(specifier) {
// Apply the scale, computing it from the value's exponent for si format.
if (scale < 0) {
var prefix = d3.formatPrefix(value, precision);
- value *= prefix.scale;
+ value = prefix.scale(value);
suffix = prefix.symbol;
} else {
value *= scale;
@@ -730,12 +730,12 @@ d3.formatPrefix = function(value, precision) {
};
function d3_formatPrefix(d, i) {
+ var k = Math.pow(10, Math.abs(8 - i) * 3);
return {
- scale: Math.pow(10, (8 - i) * 3),
+ scale: i > 8 ? function(d) { return d / k; } : function(d) { return d * k; },
symbol: d
};
}
-
/*
* TERMS OF USE - EASING EQUATIONS
*
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -43,7 +43,7 @@ d3.format = function(specifier) {
// Apply the scale, computing it from the value's exponent for si format.
if (scale < 0) {
var prefix = d3.formatPrefix(value, precision);
- value *= prefix.scale;
+ value = prefix.scale(value);
suffix = prefix.symbol;
} else {
value *= scale;
View
@@ -12,9 +12,9 @@ d3.formatPrefix = function(value, precision) {
};
function d3_formatPrefix(d, i) {
+ var k = Math.pow(10, Math.abs(8 - i) * 3);
return {
- scale: Math.pow(10, (8 - i) * 3),
+ scale: i > 8 ? function(d) { return d / k; } : function(d) { return d * k; },
symbol: d
};
}
-
View
@@ -78,6 +78,7 @@ suite.addBatch({
assert.strictEqual(f(999.5), "999.5");
assert.strictEqual(f(999500), "999.5k");
assert.strictEqual(f(1000), "1k");
+ assert.strictEqual(f(1400), "1.4k");
assert.strictEqual(f(1500.5), "1.5005k");
assert.strictEqual(f(.000001), "");
},

0 comments on commit 5fff2c3

Please sign in to comment.