@@ -23,6 +23,7 @@ export const getCurrencyHelpers = ({
2323 formatter . formatToParts ( 11111111 ) . find ( ( { type } ) => type === 'group' ) ?. value ?? '' ;
2424 const decimalSeparator =
2525 formatter . formatToParts ( 1.1 ) . find ( ( { type } ) => type === 'decimal' ) ?. value ?? '.' ;
26+ const alternativeDecimalSeparator = decimalSeparator === '.' ? ',' : '.' ;
2627 const literalSeparator =
2728 formatter . formatToParts ( 1.1 ) . find ( ( { type } ) => type === 'literal' ) ?. value ?? '' ;
2829 const decimalMultiplier = parseInt ( `1${ '0' . repeat ( decimalDigits ) } ` , 10 ) ;
@@ -78,7 +79,7 @@ export const getCurrencyHelpers = ({
7879 } ;
7980
8081 /* Sanitize input by allowing only digits, negative sign, and one decimal separator */
81- const sanitizeInput = ( input : string , signed = false ) => {
82+ const sanitizeInput = ( input : string , signed = false , alternativeDecimal = false ) => {
8283 let cleaned = '' ;
8384 let hasDecimalSeparator = false ;
8485 let hasNegativeSign = false ;
@@ -90,6 +91,16 @@ export const getCurrencyHelpers = ({
9091 hasDecimalSeparator = true ;
9192 return ;
9293 }
94+ if (
95+ alternativeDecimal &&
96+ letter === alternativeDecimalSeparator &&
97+ ! hasDecimalSeparator &&
98+ ! input . includes ( decimalSeparator )
99+ ) {
100+ cleaned += decimalSeparator ;
101+ hasDecimalSeparator = true ;
102+ return ;
103+ }
93104 // when a user presses '-' sign, switch the sign of the number
94105 if ( letter === '-' && ! hasNegativeSign ) {
95106 hasNegativeSign = true ;
0 commit comments