Skip to content

Commit

Permalink
feat: Support Chinese dot as decimal separator
Browse files Browse the repository at this point in the history
  • Loading branch information
dm4t2 committed Feb 7, 2024
1 parent e53c062 commit b4ecd1a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/currencyFormat.ts
@@ -1,7 +1,12 @@
import { escapeRegExp, substringBefore } from './utils'
import { CurrencyDisplay, CurrencyInputOptions } from './api'

export const DECIMAL_SEPARATORS = [',', '.', '٫']
export const DECIMAL_SEPARATORS = [
',', // comma
'.', // dot
'٫', // Persian Momayyez
'。' // Chinese dot
]
export const INTEGER_PATTERN = '(0|[1-9]\\d*)'

export default class CurrencyFormat {
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/currencyFormat.spec.ts
Expand Up @@ -103,9 +103,10 @@ describe('CurrencyFormat', () => {
})
})

describe('normalizeDecimalSymbol', () => {
it('should replace the first decimal symbol with the one of the current locale', () => {
describe('normalizeDecimalSeparator', () => {
it('should replace the first decimal separator with the one of the current locale', () => {
expect(new CurrencyFormat({ locale: 'en', currency: 'EUR' }).normalizeDecimalSeparator('1,23,4,567', 2)).toBe('1,23.4,567')
expect(new CurrencyFormat({ locale: 'en', currency: 'EUR' }).normalizeDecimalSeparator('1。23', 0)).toBe('1.23')
})
})

Expand Down

0 comments on commit b4ecd1a

Please sign in to comment.