Can we have the option to use both '.' and ',' as numeralDecimalMark at the same time?
So both inputs would be valid:
1930,15
3899.99
I ask this because in an 'amount' field, i don't want to restrict the user based on locales.
I can see a conflict when thousand delimiters are used as well. This would only make sense if thousand delimiters are not used.
thanks!
We have the same problem here in canada where both english and french are official languages. In french, the official decimal mark is a coma but both coma and period are commonly used by canadians.
Best behaviour I can think of would be to accept coma or period indifferently, but always input the right decimal mark according to the locale you want to display the numeric value.
Thanks for the great work !
Is it possible to add a locale option? So that we can choose a locale to decide which symbol(comma or dot) acts as thousand delimiter or fraction deliomiter.
here's an example in Java: How to change the decimal separator of DecimalFormat from comma to dot/point?
@JackEggie you can always do something like that:
`
getCurrencyDetail(locale: string): MCurrency {
const currency: MCurrencyType = this.currentCurrency;
const currencyTemplate: string = new Intl.NumberFormat(locale, { maximumSignificantDigits: 1, style: 'currency', currency: MCurrencyType[currency] }).format(0);
const localizedSymbol: string = currencyTemplate.replace('0', '').trim();
return new MCurrency(
currency,
localizedSymbol,
currencyTemplate.split(localizedSymbol)[0] === '' ? MCurrencySymbolPosition.Before : MCurrencySymbolPosition.After
);
}
`
Use Intl to your advantage :)
Also I ended up doing a simple fix to support . even if the decimal mark is ,
onKeydownTextfield($event: any): void {
const rawValue: string = this.cleave.getRawValue();
if ($event.key === '.' && !rawValue.endsWith('.')) {
this.cleave.setRawValue(${rawValue}.);
}
}
So when the user press . I check up if the raw value of cleave ends by '.'. If not I just append it and it will add the decimal mark I provided at the end of my input
@nosir any plans to implement this feature? I like Cleave.js but inability to use dots and commas as decimal separators at the same time is a dealbreaker for me.
Most helpful comment
@nosir any plans to implement this feature? I like Cleave.js but inability to use dots and commas as decimal separators at the same time is a dealbreaker for me.