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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } | 149 } |
150 _pad(_minimumExponentDigits, exponent.toString()); | 150 _pad(_minimumExponentDigits, exponent.toString()); |
151 } | 151 } |
152 | 152 |
153 /** | 153 /** |
154 * Format the basic number portion, inluding the fractional digits. | 154 * Format the basic number portion, inluding the fractional digits. |
155 */ | 155 */ |
156 void _formatFixed(num number) { | 156 void _formatFixed(num number) { |
157 // Round the number. | 157 // Round the number. |
158 var power = pow(10, _maximumFractionDigits); | 158 var power = pow(10, _maximumFractionDigits); |
159 var intValue = number.truncate().toInt(); | 159 var intValue = number.truncate(); |
160 var multiplied = (number * power).round(); | 160 var multiplied = (number * power).round(); |
161 var fracValue = (multiplied - intValue * power).floor().toInt(); | 161 var fracValue = (multiplied - intValue * power).floor(); |
162 var fractionPresent = _minimumFractionDigits > 0 || fracValue > 0; | 162 var fractionPresent = _minimumFractionDigits > 0 || fracValue > 0; |
163 | 163 |
164 // On dartj2s the integer part may be large enough to be a floating | 164 // On dartj2s the integer part may be large enough to be a floating |
165 // point value, in which case we reduce it until it is small enough | 165 // point value, in which case we reduce it until it is small enough |
166 // to be printed as an integer and pad the remainder with zeros. | 166 // to be printed as an integer and pad the remainder with zeros. |
167 var paddingDigits = new StringBuffer(); | 167 var paddingDigits = new StringBuffer(); |
168 while ((intValue & 0x7fffffff) != intValue) { | 168 while ((intValue & 0x7fffffff) != intValue) { |
169 paddingDigits.add(symbols.ZERO_DIGIT); | 169 paddingDigits.add(symbols.ZERO_DIGIT); |
170 intValue = intValue ~/ 10; | 170 intValue = intValue ~/ 10; |
171 } | 171 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |