Skip to content

Commit 22e397e

Browse files
authored
fix: Swiss currency parsing (#8546)
* fix: Swiss currency parsing * remove only * Apply suggestion from @snowystinger * add comment
1 parent 405a660 commit 22e397e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ class NumberParserImpl {
215215
}
216216
}
217217

218+
// In some locale styles, such as swiss currency, the group character can be a special single quote
219+
// that keyboards don't typically have. This expands the character to include the easier to type single quote.
220+
if (this.symbols.group === '’' && value.includes("'")) {
221+
value = replaceAll(value, "'", this.symbols.group);
222+
}
223+
218224
// fr-FR group character is narrow non-breaking space, char code 8239 (U+202F), but that's not a key on the french keyboard,
219225
// so allow space and non-breaking space as a group char as well
220226
if (this.options.locale === 'fr-FR' && this.symbols.group) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ describe('NumberParser', function () {
188188
});
189189
});
190190

191+
it('should parse a swiss currency number', () => {
192+
expect(new NumberParser('de-CH', {style: 'currency', currency: 'CHF'}).parse('CHF 1’000.00')).toBe(1000);
193+
expect(new NumberParser('de-CH', {style: 'currency', currency: 'CHF'}).parse("CHF 1'000.00")).toBe(1000);
194+
expect(new NumberParser('de-CH', {style: 'currency', currency: 'CHF'}).parse("CHF 1'000.00")).toBe(1000);
195+
});
196+
191197
describe('round trips', function () {
192198
fc.configureGlobal({numRuns: 200});
193199
// Locales have to include: 'de-DE', 'ar-EG', 'fr-FR' and possibly others

0 commit comments

Comments
 (0)