| OLD | NEW |
| 1 part of angular.filter; | 1 part of angular.formatter_internal; |
| 2 | 2 |
| 3 /** | 3 /** |
| 4 * Formats a number as text. | 4 * Formats a number as text. |
| 5 * | 5 * |
| 6 * If the input is not a number an empty string is returned. | 6 * If the input is not a number an empty string is returned. |
| 7 * | 7 * |
| 8 * | 8 * |
| 9 * Usage: | 9 * Usage: |
| 10 * | 10 * |
| 11 * {{ number_expression | number[:fractionSize] }} | 11 * {{ number_expression | number[:fractionSize] }} |
| 12 * | 12 * |
| 13 */ | 13 */ |
| 14 @NgFilter(name:'number') | 14 @Formatter(name:'number') |
| 15 class NumberFilter { | 15 class Number { |
| 16 | 16 |
| 17 Map<num, NumberFormat> nfs = new Map<num, NumberFormat>(); | 17 var _nfs = new Map<String, Map<num, NumberFormat>>(); |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * [value]: the value to format | 20 * [value]: the value to format |
| 21 * | 21 * |
| 22 * [fractionSize]: Number of decimal places to round the number to. If this | 22 * [fractionSize]: Number of decimal places to round the number to. If this |
| 23 * is not provided then the fraction size is computed from the current | 23 * is not provided then the fraction size is computed from the current |
| 24 * locale's number formatting pattern. In the case of the default locale, | 24 * locale's number formatting pattern. In the case of the default locale, |
| 25 * it will be 3. | 25 * it will be 3. |
| 26 */ | 26 */ |
| 27 call(value, [fractionSize = null]) { | 27 call(value, [fractionSize = null]) { |
| 28 if (value is String) value = double.parse(value); | 28 if (value is String) value = double.parse(value); |
| 29 if (!(value is num)) return value; | 29 if (!(value is num)) return value; |
| 30 if (value.isNaN) return ''; | 30 if (value.isNaN) return ''; |
| 31 var nf = nfs[fractionSize]; | 31 var verifiedLocale = Intl.verifiedLocale(Intl.getCurrentLocale(), NumberForm
at.localeExists); |
| 32 _nfs.putIfAbsent(verifiedLocale, () => new Map<num, NumberFormat>()); |
| 33 var nf = _nfs[verifiedLocale][fractionSize]; |
| 32 if (nf == null) { | 34 if (nf == null) { |
| 33 nf = new NumberFormat()..maximumIntegerDigits = 9; | 35 nf = new NumberFormat()..maximumIntegerDigits = 9; |
| 34 if (fractionSize != null) { | 36 if (fractionSize != null) { |
| 35 nf.minimumFractionDigits = fractionSize; | 37 nf.minimumFractionDigits = fractionSize; |
| 36 nf.maximumFractionDigits = fractionSize; | 38 nf.maximumFractionDigits = fractionSize; |
| 37 } | 39 } |
| 38 nfs[fractionSize] = nf; | 40 _nfs[verifiedLocale][fractionSize] = nf; |
| 39 } | 41 } |
| 40 return nf.format(value); | 42 return nf.format(value); |
| 41 } | 43 } |
| 42 } | 44 } |
| OLD | NEW |