@@ -82,6 +82,8 @@ function currencyFilter($locale) {
82
82
*
83
83
* If the input is not a number an empty string is returned.
84
84
*
85
+ * If the input is an infinite (Infinity/-Infinity) the Infinity symbol '∞' is returned.
86
+ *
85
87
* @param {number|string } number Number to format.
86
88
* @param {(number|string)= } fractionSize Number of decimal places to round the number to.
87
89
* If this is not provided then the fraction size is computed from the current locale's number
@@ -138,16 +140,22 @@ function numberFilter($locale) {
138
140
139
141
var DECIMAL_SEP = '.' ;
140
142
function formatNumber ( number , pattern , groupSep , decimalSep , fractionSize ) {
141
- if ( ! isFinite ( number ) || isObject ( number ) ) return '' ;
143
+ if ( isObject ( number ) ) return '' ;
142
144
143
145
var isNegative = number < 0 ;
144
146
number = Math . abs ( number ) ;
147
+
148
+ var isInfinity = number === Infinity ;
149
+ if ( ! isInfinity && ! isFinite ( number ) ) return '' ;
150
+
145
151
var numStr = number + '' ,
146
152
formatedText = '' ,
153
+ hasExponent = false ,
147
154
parts = [ ] ;
148
155
149
- var hasExponent = false ;
150
- if ( numStr . indexOf ( 'e' ) !== - 1 ) {
156
+ if ( isInfinity ) formatedText = '\u221e' ;
157
+
158
+ if ( ! isInfinity && numStr . indexOf ( 'e' ) !== - 1 ) {
151
159
var match = numStr . match ( / ( [ \d \. ] + ) e ( - ? ) ( \d + ) / ) ;
152
160
if ( match && match [ 2 ] == '-' && match [ 3 ] > fractionSize + 1 ) {
153
161
number = 0 ;
@@ -157,7 +165,7 @@ function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) {
157
165
}
158
166
}
159
167
160
- if ( ! hasExponent ) {
168
+ if ( ! isInfinity && ! hasExponent ) {
161
169
var fractionLen = ( numStr . split ( DECIMAL_SEP ) [ 1 ] || '' ) . length ;
162
170
163
171
// determine fractionSize if it is not specified
0 commit comments