Skip to content

Commit f459c18

Browse files
authored
Fix NumberParser getSymbols rounding support (#7186)
1 parent f77152e commit f459c18

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,14 @@ const pluralNumbers = [
255255

256256
function getSymbols(locale: string, formatter: Intl.NumberFormat, intlOptions: Intl.ResolvedNumberFormatOptions, originalOptions: Intl.NumberFormatOptions): Symbols {
257257
// formatter needs access to all decimal places in order to generate the correct literal strings for the plural set
258-
let symbolFormatter = new Intl.NumberFormat(locale, {...intlOptions, minimumSignificantDigits: 1, maximumSignificantDigits: 21});
258+
let symbolFormatter = new Intl.NumberFormat(locale, {...intlOptions,
259+
// Resets so we get the full range of symbols
260+
minimumSignificantDigits: 1,
261+
maximumSignificantDigits: 21,
262+
roundingIncrement: 1,
263+
roundingPriority: 'auto',
264+
roundingMode: 'halfExpand'
265+
});
259266
// Note: some locale's don't add a group symbol until there is a ten thousands place
260267
let allParts = symbolFormatter.formatToParts(-10000.111);
261268
let posAllParts = symbolFormatter.formatToParts(10000.111);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ describe('NumberParser', function () {
165165
});
166166
});
167167

168+
describe('NumberFormat options', function () {
169+
it('supports roundingIncrement', function () {
170+
expect(new NumberParser('en-US', {roundingIncrement: 2}).parse('10')).toBe(10);
171+
// This doesn't fail in Node 18 because roundingIncrement isn't on the resolved options. Hopefully later versions of Node this test will be meaningful.
172+
expect(new NumberParser('en-US', {roundingIncrement: 2, minimumFractionDigits: 2, maximumFractionDigits: 2}).parse('10.00')).toBe(10.00);
173+
});
174+
});
175+
168176
describe('round trips', function () {
169177
// Locales have to include: 'de-DE', 'ar-EG', 'fr-FR' and possibly others
170178
// But for the moment they are not properly supported

0 commit comments

Comments
 (0)