-
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 |
---|---|---|
|
@@ -59,6 +59,18 @@ describe('filters', function() { | |
expect(num).toBe('1.1112'); | ||
}); | ||
|
||
it('should format large number',function() { | ||
pattern.gsize = 2; | ||
var num = formatNumber(12345868059685210000, pattern, ',', '.', 2); | ||
expect(num).toBe('12,345,868,059,685,210,000.00'); | ||
var num = formatNumber(79832749837498327498274983793234322432, pattern, ',', '.', 2); | ||
expect(num).toBe('7.983274983749832e+37'); | ||
var num = formatNumber(8798327498374983274928, pattern, ',', '.', 2); | ||
expect(num).toBe('8.798327498374983e+21'); | ||
var num = formatNumber(879832749374983274928, pattern, ',', '.', 2); | ||
expect(num).toBe('879,832,749,374,983,200,000.00'); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
gauravaror
Author
Owner
|
||
}); | ||
|
||
it('should format according different separators', function() { | ||
var num = formatNumber(1234567.1, pattern, '.', ',', 2); | ||
expect(num).toBe('1.234.567,10'); | ||
|
1 comment
on commit 1567e58
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done with the other suggested changes, but since number is roundedoff after 16 digit, i am thinking will this change be useful.
I was trying to write some additional test cases is when i found out that .. When we apply the number filter to 879832749374983274928 we get result 879,832,749,374,983,200,000.00
Which is not a correct result since all the digits after 16 digits is being converted to zero, which is wrong.
This is happening because
They are 64-bit floating point values, the largest exact integral value is 253, or 9007199254740992
any number greater than this number will get the zeros after 16 digits and there by loose precision at the least.
this loose of precision is outside of the scope of number filter