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

Commit a118872

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 1917ff8 commit a118872

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
@@ -304,7 +304,7 @@ function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) {
304304

305305
// format the integer digits with grouping separators
306306
var groups = [];
307-
if (digits.length > pattern.lgSize) {
307+
if (digits.length >= pattern.lgSize) {
308308
groups.unshift(digits.splice(-pattern.lgSize).join(''));
309309
}
310310
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)