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