Skip to content

Commit aa43cba

Browse files
owencraigOwen Craig
authored and
Owen Craig
committed
fix(formatNumber): handle small numbers correctly different gSize and lgSize
By using >= when comparing the number length to the lgSize we'll provide the correct value when formatting numbers with differing lgSize and gSize Closes angular#14289
1 parent aa077e8 commit aa43cba

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)