Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix(numberFilter): fix rounding error edge case
Browse files Browse the repository at this point in the history
Fix a number rounding error.

Closes #7453
Closes #7478
  • Loading branch information
lgalfaso authored and petebacondarwin committed May 15, 2014
1 parent a84344a commit 81d427b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ng/filter/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) {
fractionSize = Math.min(Math.max(pattern.minFrac, fractionLen), pattern.maxFrac);
}

var pow = Math.pow(10, fractionSize);
number = Math.round(number * pow) / pow;
var pow = Math.pow(10, fractionSize + 1);
number = Math.floor(number * pow + 5) / pow;
var fraction = ('' + number).split(DECIMAL_SEP);
var whole = fraction[0];
fraction = fraction[1] || '';
Expand Down
4 changes: 4 additions & 0 deletions test/ng/filter/filtersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ describe('filters', function() {
expect(number(1234.567, 0)).toEqual("1,235");
expect(number(1234.567, 1)).toEqual("1,234.6");
expect(number(1234.567, 2)).toEqual("1,234.57");
expect(number(1.255, 0)).toEqual("1");
expect(number(1.255, 1)).toEqual("1.3");
expect(number(1.255, 2)).toEqual("1.26");
expect(number(1.255, 3)).toEqual("1.255");
});

it('should filter exponentially large numbers', function() {
Expand Down

0 comments on commit 81d427b

Please sign in to comment.