From ec09be6179f88e1b58ee0bee532d350026858380 Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Sat, 22 Nov 2014 10:50:54 -0800 Subject: [PATCH] fix($locale): Allow currency filter to fall back to maxFrac from locale - Modify default fallback to `NUMBER_FORMATS.PATTERNS[1].maxFrac` - Remove unnecessary resetting --- src/ng/filter/filters.js | 5 ++--- test/ng/filter/filtersSpec.js | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ng/filter/filters.js b/src/ng/filter/filters.js index 65de6ccea705..9406f5e8dee1 100644 --- a/src/ng/filter/filters.js +++ b/src/ng/filter/filters.js @@ -11,7 +11,7 @@ * * @param {number} amount Input to filter. * @param {string=} symbol Currency symbol or identifier to be displayed. - * @param {number=} fractionSize Number of decimal places to round the amount to. + * @param {number=} fractionSize Number of decimal places to round the amount to, defaults to default max fraction size for current locale * @returns {string} Formatted number. * * @@ -61,8 +61,7 @@ function currencyFilter($locale) { } if (isUndefined(fractionSize)) { - // TODO: read the default value from the locale file - fractionSize = 2; + fractionSize = formats.PATTERNS[1].maxFrac; } // if null or undefined pass it through diff --git a/test/ng/filter/filtersSpec.js b/test/ng/filter/filtersSpec.js index 7b23d24bb385..32554af0949b 100644 --- a/test/ng/filter/filtersSpec.js +++ b/test/ng/filter/filtersSpec.js @@ -120,6 +120,12 @@ describe('filters', function() { expect(currency(0.008)).toBe('$0.01'); expect(currency(0.003)).toBe('$0.00'); }); + + it('should set the default fraction size to the max fraction size of the locale value', inject(function($locale) { + $locale.NUMBER_FORMATS.PATTERNS[1].maxFrac = 1; + + expect(currency(1.07)).toBe('$1.1'); + })); });