Skip to content

Commit cea2ac7

Browse files
fix(formatNumber): incorrect leading group separator for locales with zero group sizes
1 parent b072a73 commit cea2ac7

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/numbers/group-integer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ export default function groupInteger(number, start, end, options, info) {
2424
groupSize = newGroupSize !== undefined ? newGroupSize : groupSize;
2525

2626
if (groupSize === 0) {
27-
parts.push(integer.substring(0, idx));
27+
value = integer.substring(0, idx);
28+
if (value) {
29+
parts.push(value);
30+
}
2831
break;
2932
}
3033
}

test/numbers.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,14 @@ describe('standard decimal formatting', () => {
233233
expect(formatNumber(33111110, "n", "custom")).toEqual("33111110");
234234
});
235235

236+
//doesn't seem to be a locale with zero group size so not sure if this is needed
237+
it('should not add group if the integer length is equal to the non-zero group sizes', () => {
238+
loadCustom({ pattern: ",,###,##0.###"});
239+
console.log(JSON.stringify(cldr.custom, null, 4));
240+
241+
expect(formatNumber(123456, "n", "custom")).toEqual("123,456");
242+
});
243+
236244
});
237245

238246
describe('standard percent formatting', () => {

0 commit comments

Comments
 (0)