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 formatting when "0" passed as fractionSize
Browse files Browse the repository at this point in the history
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."
  • Loading branch information
kkruit authored and IgorMinar committed Feb 14, 2013
1 parent f3231b9 commit f583596
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/filter/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions test/ng/filter/filtersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit f583596

Please sign in to comment.