Skip to content

Commit 3853ee7

Browse files
committed
fix: NumberParser useGrouping false returned wrong value
1 parent a0d9474 commit 3853ee7

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

packages/@internationalized/number/src/NumberParser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ function getSymbols(locale: string, formatter: Intl.NumberFormat, intlOptions: I
282282
maximumSignificantDigits: 21,
283283
roundingIncrement: 1,
284284
roundingPriority: 'auto',
285-
roundingMode: 'halfExpand'
285+
roundingMode: 'halfExpand',
286+
useGrouping: true
286287
});
287288
// Note: some locale's don't add a group symbol until there is a ten thousands place
288289
let allParts = symbolFormatter.formatToParts(-10000.111);

packages/@internationalized/number/test/NumberParser.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ describe('NumberParser', function () {
5656
expect(new NumberParser('en-US', {style: 'decimal'}).parse('1abc')).toBe(NaN);
5757
});
5858

59+
it('should return NaN for invalid grouping', function () {
60+
expect(new NumberParser('en-US', {useGrouping: false}).parse('1234,7')).toBe(12347);
61+
expect(new NumberParser('de-DE', {useGrouping: false}).parse('1234.7')).toBe(12347);
62+
});
63+
5964
describe('currency', function () {
6065
it('should parse without the currency symbol', function () {
6166
expect(new NumberParser('en-US', {currency: 'USD', style: 'currency'}).parse('10.50')).toBe(10.5);

0 commit comments

Comments
 (0)