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

Commit 4202d8a

Browse files
owencraiggkalpak
authored andcommitted
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
1 parent 27ceb6a commit 4202d8a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/ng/filter/filters.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) {
323323

324324
// format the integer digits with grouping separators
325325
var groups = [];
326-
if (digits.length > pattern.lgSize) {
326+
if (digits.length >= pattern.lgSize) {
327327
groups.unshift(digits.splice(-pattern.lgSize).join(''));
328328
}
329329
while (digits.length > pattern.gSize) {

test/ng/filter/filtersSpec.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ describe('filters', function() {
3535

3636
it('should format according to different patterns', function() {
3737
pattern.gSize = 2;
38-
var num = formatNumber(1234567.89, pattern, ',', '.');
38+
var num = formatNumber(99, pattern, ',', '.');
39+
expect(num).toBe('99');
40+
num = formatNumber(888, pattern, ',', '.');
41+
expect(num).toBe('888');
42+
num = formatNumber(1234567.89, pattern, ',', '.');
3943
expect(num).toBe('12,34,567.89');
4044
num = formatNumber(1234.56, pattern, ',', '.');
4145
expect(num).toBe('1,234.56');

0 commit comments

Comments
 (0)