Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-19 21:52:41 +00:00
co-authored by renee-png
parent 2cb756a3e9
commit 7d57bd2e3f
+19 -2
View File
@@ -84,8 +84,25 @@ const toBool = (v: any) => {
const toNum = (v: any) => {
if (v === "" || v == null) return null;
const n = Number(String(v).replace(/[$,]/g, ""));
return isNaN(n) ? null : n;
if (typeof v === "number") return isNaN(v) ? null : v;
let s = String(v).trim();
if (!s) return null;
// Accounting negatives: (123.45) → -123.45
let negative = false;
if (/^\(.*\)$/.test(s)) {
negative = true;
s = s.slice(1, -1);
}
// Strip currency symbols, commas, spaces, and stray non-numeric chars (keep . and -)
s = s.replace(/[$£€¥,\s]/g, "");
if (s.endsWith("-")) {
// trailing minus (e.g. "100-")
negative = true;
s = s.slice(0, -1);
}
const n = Number(s);
if (isNaN(n)) return null;
return negative ? -n : n;
};
const toDate = (v: any): string | null => {