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:
committed by
Georgios Kalpakas
parent
27ceb6a8fc
commit
4202d8a5de
@@ -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) {
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user