| OLD | NEW |
| (Empty) |
| 1 part of angular.formatter_internal; | |
| 2 | |
| 3 /** | |
| 4 * Formats a number as a currency (ie $1,234.56). When no currency symbol is | |
| 5 * provided, '$' used. | |
| 6 * | |
| 7 * | |
| 8 * Usage: | |
| 9 * | |
| 10 * {{ numeric_expression | currency[:symbol[:leading]] }} | |
| 11 * | |
| 12 */ | |
| 13 @Formatter(name:'currency') | |
| 14 class Currency implements Function { | |
| 15 | |
| 16 var _nfs = new Map<String, NumberFormat>(); | |
| 17 | |
| 18 /** | |
| 19 * [value]: the value to format | |
| 20 * | |
| 21 * [symbol]: Symbol to use. | |
| 22 * | |
| 23 * [leading]: Symbol should be placed in front of the number | |
| 24 */ | |
| 25 call(value, [symbol = r'$', leading = true]) { | |
| 26 if (value is String) value = double.parse(value); | |
| 27 if (value is! num) return value; | |
| 28 if (value.isNaN) return ''; | |
| 29 var verifiedLocale = Intl.verifiedLocale(Intl.getCurrentLocale(), NumberForm
at.localeExists); | |
| 30 var nf = _nfs[verifiedLocale]; | |
| 31 if (nf == null) { | |
| 32 nf = new NumberFormat(); | |
| 33 nf.minimumFractionDigits = 2; | |
| 34 nf.maximumFractionDigits = 2; | |
| 35 _nfs[verifiedLocale] = nf; | |
| 36 } | |
| 37 var neg = value < 0; | |
| 38 if (neg) value = -value; | |
| 39 var before = neg ? '(' : ''; | |
| 40 var after = neg ? ')' : ''; | |
| 41 return leading ? | |
| 42 '$before$symbol${nf.format(value)}$after' : | |
| 43 '$before${nf.format(value)}$symbol$after'; | |
| 44 } | |
| 45 } | |
| OLD | NEW |