Skip to content

Commit

Permalink
Merge branch 'fix-si-format-rounding' into 2.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed May 16, 2012
2 parents 7827bdc + 00bc3f0 commit 5fff2c3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions d3.v2.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down
8 changes: 4 additions & 4 deletions d3.v2.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/core/format.js
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/core/formatPrefix.js
Expand Up @@ -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
};
}

1 change: 1 addition & 0 deletions test/core/format-test.js
Expand Up @@ -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), "1μ");
},
Expand Down

0 comments on commit 5fff2c3

Please sign in to comment.