fix(formatNumber): handle small numbers correctly when gSize !== lgSize

By using `>=` when comparing the number length to `lgSize`, we'll provide the correct value, when
formatting numbers with different `lgSize` than `gSize`.

Fixes #14289

Closes #14290
This commit is contained in:
Owen Craig
2016-03-21 14:29:18 -05:00
committed by Georgios Kalpakas
parent 27ceb6a8fc
commit 4202d8a5de
2 changed files with 6 additions and 2 deletions
+1 -1
View File
@@ -323,7 +323,7 @@ function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) {
// format the integer digits with grouping separators
var groups = [];
if (digits.length > pattern.lgSize) {
if (digits.length >= pattern.lgSize) {
groups.unshift(digits.splice(-pattern.lgSize).join(''));
}
while (digits.length > pattern.gSize) {
+5 -1
View File
@@ -35,7 +35,11 @@ describe('filters', function() {
it('should format according to different patterns', function() {
pattern.gSize = 2;
var num = formatNumber(1234567.89, pattern, ',', '.');
var num = formatNumber(99, pattern, ',', '.');
expect(num).toBe('99');
num = formatNumber(888, pattern, ',', '.');
expect(num).toBe('888');
num = formatNumber(1234567.89, pattern, ',', '.');
expect(num).toBe('12,34,567.89');
num = formatNumber(1234.56, pattern, ',', '.');
expect(num).toBe('1,234.56');