mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
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."
This commit is contained in:
parent
d67eb2f2db
commit
75545d4d1c
2 changed files with 12 additions and 1 deletions
|
|
@ -168,7 +168,7 @@ function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) {
|
|||
fraction += '0';
|
||||
}
|
||||
|
||||
if (fractionSize) formatedText += decimalSep + fraction.substr(0, fractionSize);
|
||||
if (fractionSize && fractionSize !== "0") formatedText += decimalSep + fraction.substr(0, fractionSize);
|
||||
}
|
||||
|
||||
parts.push(isNegative ? pattern.negPre : pattern.posPre);
|
||||
|
|
|
|||
|
|
@ -71,6 +71,17 @@ describe('filters', function() {
|
|||
var num = formatNumber(123.1116, pattern, ',', '.');
|
||||
expect(num).toBe('123.112');
|
||||
});
|
||||
|
||||
it('should format the same with string as well as numeric fractionSize', function(){
|
||||
var num = formatNumber(123.1, pattern, ',', '.', "0");
|
||||
expect(num).toBe('123');
|
||||
var num = formatNumber(123.1, pattern, ',', '.', 0);
|
||||
expect(num).toBe('123');
|
||||
var num = formatNumber(123.1, pattern, ',', '.', "3");
|
||||
expect(num).toBe('123.100');
|
||||
var num = formatNumber(123.1, pattern, ',', '.', 3);
|
||||
expect(num).toBe('123.100');
|
||||
});
|
||||
});
|
||||
|
||||
describe('currency', function() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue