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

Commit 81d427b

Browse files
lgalfasopetebacondarwin
authored andcommittedMay 15, 2014
fix(numberFilter): fix rounding error edge case
Fix a number rounding error. Closes #7453 Closes #7478
1 parent a84344a commit 81d427b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed
 

‎src/ng/filter/filters.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) {
145145
fractionSize = Math.min(Math.max(pattern.minFrac, fractionLen), pattern.maxFrac);
146146
}
147147

148-
var pow = Math.pow(10, fractionSize);
149-
number = Math.round(number * pow) / pow;
148+
var pow = Math.pow(10, fractionSize + 1);
149+
number = Math.floor(number * pow + 5) / pow;
150150
var fraction = ('' + number).split(DECIMAL_SEP);
151151
var whole = fraction[0];
152152
fraction = fraction[1] || '';

‎test/ng/filter/filtersSpec.js

+4
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ describe('filters', function() {
150150
expect(number(1234.567, 0)).toEqual("1,235");
151151
expect(number(1234.567, 1)).toEqual("1,234.6");
152152
expect(number(1234.567, 2)).toEqual("1,234.57");
153+
expect(number(1.255, 0)).toEqual("1");
154+
expect(number(1.255, 1)).toEqual("1.3");
155+
expect(number(1.255, 2)).toEqual("1.26");
156+
expect(number(1.255, 3)).toEqual("1.255");
153157
});
154158

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

0 commit comments

Comments
 (0)
This repository has been archived.