Skip to content

Commit

Permalink
Merge pull request #151 from jolelievre/fix-cldr-negative
Browse files Browse the repository at this point in the history
Fix CLDR number formatter for negative values
  • Loading branch information
PierreRambaud committed Dec 11, 2019
2 parents 6e5c5ab + a116cd6 commit 30eb649
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions _dev/cldr/number-formatter.js
Expand Up @@ -80,7 +80,7 @@ class NumberFormatter {
}

// Get the good CLDR formatting pattern. Sign is important here !
const pattern = this.getCldrPattern(majorDigits < 0);
const pattern = this.getCldrPattern(number < 0);
formattedNumber = this.addPlaceholders(formattedNumber, pattern);
formattedNumber = this.replaceSymbols(formattedNumber);

Expand Down Expand Up @@ -277,7 +277,13 @@ class NumberFormatter {
}

static build(specifications) {
const symbol = new NumberSymbol(...specifications.symbol);
let symbol;
if (undefined !== specifications.numberSymbols) {
symbol = new NumberSymbol(...specifications.numberSymbols);
} else {
symbol = new NumberSymbol(...specifications.symbol);
}

let specification;
if (specifications.currencySymbol) {
specification = new PriceSpecification(
Expand Down
3 changes: 3 additions & 0 deletions tests/js/cldr/number-formatter.spec.js
Expand Up @@ -143,6 +143,9 @@ describe('NumberFormatter', () => {
['1000000', '$1,000,000.000'],
['10000000', '$10,000,000.000'],
['100000000', '$100,000,000.000'],
['-10.3', '-$10.300'],
['-125.45672', '-$125.457'],
['-125.45627', '-$125.456'],
];
assertions.forEach((assertion) => {
it(`test ${assertion[0]} should display ${assertion[1]}`, () => {
Expand Down

0 comments on commit 30eb649

Please sign in to comment.