OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #library("number_format"); | 5 #library("number_format"); |
6 | 6 |
7 #import('dart:math'); | 7 #import('dart:math'); |
8 | 8 |
9 #import("intl.dart"); | 9 #import("intl.dart"); |
10 #import("number_symbols.dart"); | 10 #import("number_symbols.dart"); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 83 |
84 // TODO(alanknight): Actually use the pattern and locale. | 84 // TODO(alanknight): Actually use the pattern and locale. |
85 _setPattern(String x) {} | 85 _setPattern(String x) {} |
86 | 86 |
87 /** | 87 /** |
88 * Format [number] according to our pattern and return the formatted string. | 88 * Format [number] according to our pattern and return the formatted string. |
89 */ | 89 */ |
90 String format(num number) { | 90 String format(num number) { |
91 // TODO(alanknight): Do we have to do anything for printing numbers bidi? | 91 // TODO(alanknight): Do we have to do anything for printing numbers bidi? |
92 // Or are they always printed left to right? | 92 // Or are they always printed left to right? |
93 if (number.isNaN()) return symbols.NAN; | 93 if (number.isNaN) return symbols.NAN; |
94 if (number.isInfinite()) return "${_signPrefix(number)}${symbols.INFINITY}"; | 94 if (number.isInfinite) return "${_signPrefix(number)}${symbols.INFINITY}"; |
95 | 95 |
96 _newBuffer(); | 96 _newBuffer(); |
97 _add(_signPrefix(number)); | 97 _add(_signPrefix(number)); |
98 _formatNumber(number.abs()); | 98 _formatNumber(number.abs()); |
99 _add(_signSuffix(number)); | 99 _add(_signSuffix(number)); |
100 | 100 |
101 var result = _buffer.toString(); | 101 var result = _buffer.toString(); |
102 _buffer = null; | 102 _buffer = null; |
103 return result; | 103 return result; |
104 } | 104 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 int get _zero => '0'.charCodes()[0]; | 261 int get _zero => '0'.charCodes()[0]; |
262 | 262 |
263 /** Returns the code point for the locale's zero digit. */ | 263 /** Returns the code point for the locale's zero digit. */ |
264 int get _localeZero => symbols.ZERO_DIGIT.charCodeAt(0); | 264 int get _localeZero => symbols.ZERO_DIGIT.charCodeAt(0); |
265 | 265 |
266 /** | 266 /** |
267 * Returns the prefix for [x] based on whether it's positive or negative. | 267 * Returns the prefix for [x] based on whether it's positive or negative. |
268 * In en_US this would be '' and '-' respectively. | 268 * In en_US this would be '' and '-' respectively. |
269 */ | 269 */ |
270 String _signPrefix(num x) { | 270 String _signPrefix(num x) { |
271 return x.isNegative() ? _negativePrefix : _positivePrefix; | 271 return x.isNegative ? _negativePrefix : _positivePrefix; |
272 } | 272 } |
273 | 273 |
274 /** | 274 /** |
275 * Returns the suffix for [x] based on wether it's positive or negative. | 275 * Returns the suffix for [x] based on wether it's positive or negative. |
276 * In en_US there are no suffixes for positive or negative. | 276 * In en_US there are no suffixes for positive or negative. |
277 */ | 277 */ |
278 String _signSuffix(num x) { | 278 String _signSuffix(num x) { |
279 return x.isNegative() ? _negativeSuffix : _positiveSuffix; | 279 return x.isNegative ? _negativeSuffix : _positiveSuffix; |
280 } | 280 } |
281 } | 281 } |
OLD | NEW |