@@ -148,13 +148,13 @@ function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) {
148
148
149
149
var hasExponent = false ;
150
150
if ( numStr . indexOf ( 'e' ) !== - 1 ) {
151
+ hasExponent = true ;
151
152
var match = numStr . match ( / ( [ \d \. ] + ) e ( - ? ) ( \d + ) / ) ;
152
- if ( match && match [ 2 ] == '-' && match [ 3 ] > fractionSize + 1 ) {
153
+ if ( match && match [ 2 ] == '-' && match [ 3 ] > ( fractionSize || pattern . maxFrac ) + 1 ) {
153
154
numStr = '0' ;
154
155
number = 0 ;
155
156
} else {
156
157
formatedText = numStr ;
157
- hasExponent = true ;
158
158
}
159
159
}
160
160
@@ -171,10 +171,6 @@ function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) {
171
171
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round
172
172
number = + ( Math . round ( + ( number . toString ( ) + 'e' + fractionSize ) ) . toString ( ) + 'e' + - fractionSize ) ;
173
173
174
- if ( number === 0 ) {
175
- isNegative = false ;
176
- }
177
-
178
174
var fraction = ( '' + number ) . split ( DECIMAL_SEP ) ;
179
175
var whole = fraction [ 0 ] ;
180
176
fraction = fraction [ 1 ] || '' ;
@@ -207,12 +203,16 @@ function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) {
207
203
208
204
if ( fractionSize && fractionSize !== "0" ) formatedText += decimalSep + fraction . substr ( 0 , fractionSize ) ;
209
205
} else {
210
-
211
- if ( fractionSize > 0 && number > - 1 && number < 1 ) {
206
+ fractionSize = isUndefined ( fractionSize ) ? pattern . maxFrac : fractionSize ;
207
+ if ( number > - 1 && number < 1 ) {
212
208
formatedText = number . toFixed ( fractionSize ) ;
213
209
}
214
210
}
215
211
212
+ if ( number === 0 ) {
213
+ isNegative = false ;
214
+ }
215
+
216
216
parts . push ( isNegative ? pattern . negPre : pattern . posPre ,
217
217
formatedText ,
218
218
isNegative ? pattern . negSuf : pattern . posSuf ) ;
0 commit comments