Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: pkg/intl/lib/number_format.dart

Issue 11748016: Make ~/, round, ceil, floor, truncate return ints. Remove toInt. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Checked mode fixes. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698