-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
format large number to correct form instead of NAN.00 currently. in previous code when first time we add the exponent with fractionSize (number.toString()+'e'+fractionsize) and then convert it to an integer using , +(number.toString()+'e'+fractionsize) when the number is very large and number will be represented by using exponent. for example 12345868059685210000 will be represented by 1.234586805968521e+21. as getting string in exponent is not handles, we get the number as NAN. Handle when the number is being represented in exponent form, by adjusting exponent of number with fraction size: Closes angular#8674
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,12 @@ function numberFilter($locale) { | |
}; | ||
} | ||
|
||
function getExponentString(numberString,fractionSize) { | ||
var numberArray = numberString.split('e'), | ||
fractionUsed = +fractionSize; | ||
return (numberArray[0] + 'e' + (numberArray[1] ? (+numberArray[1] + fractionUsed) : fractionUsed)); | ||
} | ||
|
||
var DECIMAL_SEP = '.'; | ||
function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) { | ||
if (number == null || !isFinite(number) || isObject(number)) return ''; | ||
|
@@ -151,7 +157,7 @@ function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) { | |
// safely round numbers in JS without hitting imprecisions of floating-point arithmetics | ||
// inspired by: | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round | ||
number = +(Math.round(+(number.toString() + 'e' + fractionSize)).toString() + 'e' + -fractionSize); | ||
number = +(getExponentString(Math.round(+(getExponentString(number.toString(),fractionSize))).toString(),-fractionSize)); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
gauravaror
Author
Owner
|
||
|
||
var fraction = ('' + number).split(DECIMAL_SEP); | ||
This comment has been minimized.
Sorry, something went wrong.
jbedard
|
||
var whole = fraction[0]; | ||
|
if
getExponentString
does the casting from a string to a number, then this line would be a lot easier to read (and rename the function so the name represents what it does)