Fix French decimal separator handling in money input fields

Number.parseFloat() only recognizes dots as decimal separators, causing
inputs like "256,54" (French locale) to be parsed as "256". Added a
parseLocaleFloat utility that detects whether comma or dot is the decimal
separator and normalizes accordingly before parsing.

Fixes #1138

https://claude.ai/code/session_01ThfszjiCmbDDPyb4TZqk2X
This commit is contained in:
Claude
2026-03-07 10:17:27 +00:00
parent df650b0284
commit 144d99b6e4
5 changed files with 30 additions and 10 deletions

View File

@@ -0,0 +1,17 @@
// Parses a float from a string that may use either commas or dots as decimal separators.
// Handles formats like "1,234.56" (English) and "1.234,56" (French/European).
export default function parseLocaleFloat(value) {
if (typeof value !== "string") return Number.parseFloat(value) || 0
const cleaned = value.replace(/\s/g, "")
const lastComma = cleaned.lastIndexOf(",")
const lastDot = cleaned.lastIndexOf(".")
if (lastComma > lastDot) {
// Comma is the decimal separator (e.g., "1.234,56" or "256,54")
return Number.parseFloat(cleaned.replace(/\./g, "").replace(",", ".")) || 0
}
// Dot is the decimal separator (e.g., "1,234.56" or "256.54")
return Number.parseFloat(cleaned.replace(/,/g, "")) || 0
}