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

@@ -1,4 +1,5 @@
import { Controller } from "@hotwired/stimulus"
import parseLocaleFloat from "utils/parse_locale_float"
// Handles bidirectional conversion between total cost basis and per-share cost
// in the manual cost basis entry form.
@@ -9,7 +10,7 @@ export default class extends Controller {
// Called when user types in the total cost basis field
// Updates the per-share display and input to show the calculated value
updatePerShare() {
const total = Number.parseFloat(this.totalTarget.value) || 0
const total = parseLocaleFloat(this.totalTarget.value)
const qty = this.qtyValue || 1
const perShare = qty > 0 ? (total / qty).toFixed(2) : "0.00"
this.perShareValueTarget.textContent = perShare
@@ -21,7 +22,7 @@ export default class extends Controller {
// Called when user types in the per-share field
// Updates the total cost basis field with the calculated value
updateTotal() {
const perShare = Number.parseFloat(this.perShareTarget.value) || 0
const perShare = parseLocaleFloat(this.perShareTarget.value)
const qty = this.qtyValue || 1
const total = (perShare * qty).toFixed(2)
this.totalTarget.value = total