Skip to content

Commit 5c3d51c

Browse files
committed
Merge branch 'master' of github.com:jbblanchet/d3 into fix-prefix
2 parents aaa3585 + d42e8c7 commit 5c3d51c

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/locale/number-format.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ function d3_locale_numberFormat(locale) {
7474
var zcomma = zfill && comma;
7575

7676
return function(value) {
77+
// Local variable to prevent side effect
78+
var localSuffix = suffix;
7779

7880
// Return the empty string for floats formatted as ints.
7981
if (integer && (value % 1)) return "";
@@ -85,7 +87,7 @@ function d3_locale_numberFormat(locale) {
8587
if (scale < 0) {
8688
var unit = d3.formatPrefix(value, precision);
8789
value = unit.scale(value);
88-
suffix = unit.symbol;
90+
localSuffix = unit.symbol + localSuffix;
8991
} else {
9092
value *= scale;
9193
}
@@ -116,7 +118,7 @@ function d3_locale_numberFormat(locale) {
116118
return (align === "<" ? negative + value + padding
117119
: align === ">" ? padding + negative + value
118120
: align === "^" ? padding.substring(0, length >>= 1) + negative + value + padding.substring(length)
119-
: negative + (zcomma ? value : padding + value)) + suffix;
121+
: negative + (zcomma ? value : padding + value)) + localSuffix;
120122
};
121123
};
122124
}

test/locale/locale-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ suite.addBatch({
2121
"formats currencies": function(format) {
2222
var f = format("$,.2f");
2323
assert.equal(f(12345.67), "12 345,67 руб.");
24+
},
25+
"formats currencies": function(format) {
26+
var f = format("$,.4s");
27+
assert.equal(f(12345.67), "12,35k руб.");
2428
}
29+
2530
},
2631

2732
"timeFormat": {

0 commit comments

Comments
 (0)