| 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 var power = pow(10, _maximumFractionDigits); | 149 var power = pow(10, _maximumFractionDigits); |
| 150 var intValue = number.truncate().toInt(); | 150 var intValue = number.truncate().toInt(); |
| 151 var multiplied = (number * power).round(); | 151 var multiplied = (number * power).round(); |
| 152 var fracValue = (multiplied - intValue * power).floor().toInt(); | 152 var fracValue = (multiplied - intValue * power).floor().toInt(); |
| 153 var fractionPresent = _minimumFractionDigits > 0 || fracValue > 0; | 153 var fractionPresent = _minimumFractionDigits > 0 || fracValue > 0; |
| 154 | 154 |
| 155 // On dartj2s the integer part may be large enough to be a floating | 155 // On dartj2s the integer part may be large enough to be a floating |
| 156 // point value, in which case we reduce it until it is small enough | 156 // point value, in which case we reduce it until it is small enough |
| 157 // to be printed as an integer and pad the remainder with zeros. | 157 // to be printed as an integer and pad the remainder with zeros. |
| 158 var paddingDigits = new StringBuffer(); | 158 var paddingDigits = new StringBuffer(); |
| 159 while (intValue is! int) { | 159 while ((intValue & 0x7fffffff) != intValue) { |
| 160 paddingDigits.add(symbols.ZERO_DIGIT); | 160 paddingDigits.add(symbols.ZERO_DIGIT); |
| 161 intValue = (intValue / 10).toInt(); | 161 intValue = (intValue / 10).toInt(); |
| 162 } | 162 } |
| 163 var integerDigits = "${intValue}${paddingDigits}".charCodes(); | 163 var integerDigits = "${intValue}${paddingDigits}".charCodes(); |
| 164 var digitLength = integerDigits.length; | 164 var digitLength = integerDigits.length; |
| 165 | 165 |
| 166 if (_hasPrintableIntegerPart(intValue)) { | 166 if (_hasPrintableIntegerPart(intValue)) { |
| 167 _pad(_minimumIntegerDigits - digitLength); | 167 _pad(_minimumIntegerDigits - digitLength); |
| 168 for (var i = 0; i < digitLength; i++) { | 168 for (var i = 0; i < digitLength; i++) { |
| 169 _addDigit(integerDigits[i]); | 169 _addDigit(integerDigits[i]); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 } | 263 } |
| 264 | 264 |
| 265 /** | 265 /** |
| 266 * Returns the suffix for [x] based on wether it's positive or negative. | 266 * Returns the suffix for [x] based on wether it's positive or negative. |
| 267 * In en_US there are no suffixes for positive or negative. | 267 * In en_US there are no suffixes for positive or negative. |
| 268 */ | 268 */ |
| 269 String _signSuffix(num x) { | 269 String _signSuffix(num x) { |
| 270 return x.isNegative() ? _negativeSuffix : _positiveSuffix; | 270 return x.isNegative() ? _negativeSuffix : _positiveSuffix; |
| 271 } | 271 } |
| 272 } | 272 } |
| OLD | NEW |