Client: Improved form number parser
This commit is contained in:
@@ -6,5 +6,15 @@ export function numberFormatter(value: number | undefined) {
|
||||
|
||||
// Number parser that supports both comma and dot as decimal separator
|
||||
export function numberParser(value: string | undefined) {
|
||||
return Number(value?.replace(",", ".") ?? 0);
|
||||
// Convert comma to dot
|
||||
const decimalSeparator = (1.1).toLocaleString().charAt(1);
|
||||
if (decimalSeparator === ",") {
|
||||
value = value?.replace(",", ".");
|
||||
}
|
||||
|
||||
// Remove all non-digit characters
|
||||
value = value?.replace(/[^\d.-]/g, "");
|
||||
|
||||
// Parse as float
|
||||
return parseFloat(value || "0");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user