-
Notifications
You must be signed in to change notification settings - Fork 30
feat: support European-style decimal separators in string input #238
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Summary
Add optional support for European-style number formatting in string inputs, where commas are decimal separators and periods are thousands separators.
Background
Currently, n2words accepts string inputs but only recognizes JavaScript number format (period as decimal separator):
toCardinal('1234.56') // ✓ Works: "one thousand two hundred thirty-four point five six"
toCardinal('1234,56') // ✗ Throws: Invalid number formatMany locales use comma as the decimal separator:
- Comma decimal: Germany, France, Spain, Italy, Brazil, most of Europe and South America
- Period decimal: US, UK, China, Japan, Australia
Proposed API
Option 1: Per-call option
toCardinal('1.234,56', { locale: 'de' }) // German format
toCardinal('1,234.56', { locale: 'en' }) // US format (default)Option 2: Explicit separator option
toCardinal('1.234,56', { decimalSeparator: ',' })Option 3: Auto-detection (risky - ambiguous cases like 1,234)
toCardinal('1.234,56') // Auto-detect European formatConsiderations
- Ambiguity:
1,234could be "one thousand two hundred thirty-four" (US) or "one point two three four" (EU) - Complexity: Adds parsing complexity for a feature that may have limited use
- Alternative: Users can pre-process strings before passing to n2words
- Scope: Should this apply to all forms (cardinal, ordinal, currency)?
Questions to Resolve
- Is this a common enough need to add to the library?
- Should detection be automatic or explicit?
- What's the priority vs other features?
Related
- Current parsing utilities:
src/utils/parse-cardinal.js,src/utils/parse-currency.js - String input is already supported but only in JS number format
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request