Skip to content

Commit 4c95488

Browse files
authored
Fix decimals in percent number fields without minimumFractionDigits (#2224)
1 parent 6e335ae commit 4c95488

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ const nonLiteralParts = new Set(['decimal', 'fraction', 'integer', 'minusSign',
193193

194194
function getSymbols(formatter: Intl.NumberFormat, intlOptions: Intl.ResolvedNumberFormatOptions, originalOptions: Intl.NumberFormatOptions): Symbols {
195195
// Note: some locale's don't add a group symbol until there is a ten thousands place
196-
let allParts = formatter.formatToParts(-10000.1);
197-
let posAllParts = formatter.formatToParts(10000.1);
196+
let allParts = formatter.formatToParts(-10000.111);
197+
let posAllParts = formatter.formatToParts(10000.111);
198198
let singularParts = formatter.formatToParts(1);
199199

200200
let minusSign = allParts.find(p => p.type === 'minusSign')?.value ?? '-';

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,11 @@ describe('NumberParser', function () {
251251
expect(new NumberParser('en-US', {style: 'percent'}).isValidPartialNumber('10')).toBe(true);
252252
expect(new NumberParser('en-US', {style: 'percent'}).isValidPartialNumber('10.5')).toBe(false);
253253
expect(new NumberParser('en-US', {style: 'percent', minimumFractionDigits: 2}).isValidPartialNumber('10.5')).toBe(true);
254+
expect(new NumberParser('en-US', {style: 'percent', maximumFractionDigits: 2}).isValidPartialNumber('10.5')).toBe(true);
254255
expect(new NumberParser('en-US', {style: 'percent'}).isValidPartialNumber('10%')).toBe(true);
255256
expect(new NumberParser('en-US', {style: 'percent'}).isValidPartialNumber('10.5%')).toBe(false);
256257
expect(new NumberParser('en-US', {style: 'percent', minimumFractionDigits: 2}).isValidPartialNumber('10.5%')).toBe(true);
258+
expect(new NumberParser('en-US', {style: 'percent', maximumFractionDigits: 2}).isValidPartialNumber('10.5%')).toBe(true);
257259
expect(new NumberParser('en-US', {style: 'percent'}).isValidPartialNumber('%')).toBe(true);
258260
expect(new NumberParser('en-US', {style: 'percent'}).isValidPartialNumber('10 %')).toBe(true);
259261
});

0 commit comments

Comments
 (0)