Adapt holdings to number inputs (#1258)

* Adapt holdings to number inputs

* Reviews

* FIX a small provider hardcoded name

* PR l10n request

---------

Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
soky srm
2026-03-23 18:27:53 +01:00
committed by GitHub
parent 20f279875e
commit c7b9bc48bc
18 changed files with 131 additions and 16 deletions

View File

@@ -1,9 +1,22 @@
// 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) {
//
// When a `separator` hint is provided (e.g., from currency metadata), parsing is
// deterministic. Without a hint, a heuristic detects the format from the string.
export default function parseLocaleFloat(value, { separator } = {}) {
if (typeof value !== "string") return Number.parseFloat(value) || 0
const cleaned = value.replace(/\s/g, "")
// Deterministic parsing when the currency's decimal separator is known
if (separator === ",") {
return Number.parseFloat(cleaned.replace(/\./g, "").replace(",", ".")) || 0
}
if (separator === ".") {
return Number.parseFloat(cleaned.replace(/,/g, "")) || 0
}
// Heuristic: detect separator from the string when no hint is available
const lastComma = cleaned.lastIndexOf(",")
const lastDot = cleaned.lastIndexOf(".")