@@ -82,6 +82,8 @@ function currencyFilter($locale) {
8282 *
8383 * If the input is not a number an empty string is returned.
8484 *
85+ * If the input is an infinite (Infinity/-Infinity) the Infinity symbol '∞' is returned.
86+ *
8587 * @param {number|string } number Number to format.
8688 * @param {(number|string)= } fractionSize Number of decimal places to round the number to.
8789 * If this is not provided then the fraction size is computed from the current locale's number
@@ -138,16 +140,22 @@ function numberFilter($locale) {
138140
139141var DECIMAL_SEP = '.' ;
140142function formatNumber ( number , pattern , groupSep , decimalSep , fractionSize ) {
141- if ( ! isFinite ( number ) || isObject ( number ) ) return '' ;
143+ if ( isObject ( number ) ) return '' ;
142144
143145 var isNegative = number < 0 ;
144146 number = Math . abs ( number ) ;
147+
148+ var isInfinity = number === Infinity ;
149+ if ( ! isInfinity && ! isFinite ( number ) ) return '' ;
150+
145151 var numStr = number + '' ,
146152 formatedText = '' ,
153+ hasExponent = false ,
147154 parts = [ ] ;
148155
149- var hasExponent = false ;
150- if ( numStr . indexOf ( 'e' ) !== - 1 ) {
156+ if ( isInfinity ) formatedText = '\u221e' ;
157+
158+ if ( ! isInfinity && numStr . indexOf ( 'e' ) !== - 1 ) {
151159 var match = numStr . match ( / ( [ \d \. ] + ) e ( - ? ) ( \d + ) / ) ;
152160 if ( match && match [ 2 ] == '-' && match [ 3 ] > fractionSize + 1 ) {
153161 number = 0 ;
@@ -157,7 +165,7 @@ function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) {
157165 }
158166 }
159167
160- if ( ! hasExponent ) {
168+ if ( ! isInfinity && ! hasExponent ) {
161169 var fractionLen = ( numStr . split ( DECIMAL_SEP ) [ 1 ] || '' ) . length ;
162170
163171 // determine fractionSize if it is not specified
0 commit comments