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

Commit f583596

Browse files
kkruitIgorMinar
authored andcommitted
fix(numberFilter): fix formatting when "0" passed as fractionSize
When checking to add decimal and trialing 0s number filter used to check trueness of fractionSize. "0" evaluating to true causes "123" to return "123."
1 parent f3231b9 commit f583596

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/ng/filter/filters.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) {
168168
fraction += '0';
169169
}
170170

171-
if (fractionSize) formatedText += decimalSep + fraction.substr(0, fractionSize);
171+
if (fractionSize && fractionSize !== "0") formatedText += decimalSep + fraction.substr(0, fractionSize);
172172
}
173173

174174
parts.push(isNegative ? pattern.negPre : pattern.posPre);

test/ng/filter/filtersSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ describe('filters', function() {
7171
var num = formatNumber(123.1116, pattern, ',', '.');
7272
expect(num).toBe('123.112');
7373
});
74+
75+
it('should format the same with string as well as numeric fractionSize', function(){
76+
var num = formatNumber(123.1, pattern, ',', '.', "0");
77+
expect(num).toBe('123');
78+
var num = formatNumber(123.1, pattern, ',', '.', 0);
79+
expect(num).toBe('123');
80+
var num = formatNumber(123.1, pattern, ',', '.', "3");
81+
expect(num).toBe('123.100');
82+
var num = formatNumber(123.1, pattern, ',', '.', 3);
83+
expect(num).toBe('123.100');
84+
});
7485
});
7586

7687
describe('currency', function() {

0 commit comments

Comments
 (0)