Skip to content

Commit b4ecd1a

Browse files
committed
feat: Support Chinese dot as decimal separator
1 parent e53c062 commit b4ecd1a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/currencyFormat.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { escapeRegExp, substringBefore } from './utils'
22
import { CurrencyDisplay, CurrencyInputOptions } from './api'
33

4-
export const DECIMAL_SEPARATORS = [',', '.', '٫']
4+
export const DECIMAL_SEPARATORS = [
5+
',', // comma
6+
'.', // dot
7+
'٫', // Persian Momayyez
8+
'。' // Chinese dot
9+
]
510
export const INTEGER_PATTERN = '(0|[1-9]\\d*)'
611

712
export default class CurrencyFormat {

tests/unit/currencyFormat.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ describe('CurrencyFormat', () => {
103103
})
104104
})
105105

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

0 commit comments

Comments
 (0)