29,99 read as 2,999: the comma our CSV importers got wrong

Two CSV importers stripped every comma from money, so an EU-locale 29,99 became 2,999. The fix reads the comma by shape; a CI ratchet stops new copies.

Most of the number parsers in this repository's tools clean up a money cell the same way:

Number(cell.replace(/[$,\s]/g, ""))

That reads $1,200.50 as 1200.5. It also reads 29,99 as 2999, with no error. 29,99 is how a sheet set to a German, French, Spanish or Italian locale writes 29.99. Today's red-team run fed two importers exactly that:

  • mrr-pulse, the Stripe MRR dashboard, has a CSV import that reads amounts in major units. A plan written as "29,99" came in as $2,999 a month, 100 times too high. "1.234,56" came in as $1.23, 1,000 times too low. The same importer read an interval count of 3 months or 0 as 1, so a quarterly price was counted as monthly: three times its MRR.
  • etsy-ads-roi-analyzer strips € from its numbers, so it expects euro amounts, yet €29,99 came back as 2999.

Read the comma by its shape

A thousands comma always comes before a group of exactly three digits. A decimal comma comes before one or two digits at the end. Anything else is ambiguous, and an importer should say so instead of guessing:

CellBeforeAfter
1,200.501200.51200.5
1,234,56712345671234567
29,99299929.99
1.234,561.234561234.56
12,3456123456skipped: "amount is not a number"
1,2,3123skipped: "amount is not a number"

In code:

if (/^\d{1,3}(,\d{3})+(\.\d+)?$/.test(x)) return Number(x.replace(/,/g, ""));
if (/^(\d+|\d{1,3}(\.\d{3})+),\d{1,2}$/.test(x)) return Number(x.replace(/\./g, "").replace(",", "."));
return NaN; // the row is skipped with a reason

One case stays ambiguous: 1,234 could be one thousand two hundred and thirty-four, or 1.234 written with a decimal comma. Money rarely has three decimal places, so it reads as thousands, which is what both tools did before.

Stopping the next copy

The same replace sits in 355 places across 340 venture files that mention CSV. Many of them only ever see US exports, so they are not all bugs, and rewriting all of them in one run would be guessing. Instead the run added platform/ci/check_money_comma.py, a ratchet like the repository's other tree checks. It records how many comma-stripping parsers each file has today. A file that gains one fails CI, and a file that loses one has to lower its line, so the list only shrinks. It runs on every venture pull request without a new workflow, because unwired_checks.py picks up any check_*.py that no workflow names.

The mutation numbers

The run also seeded 18 faults into two files: mrr-pulse's metrics.mjs (8) and rrule-explainer's rrule.mjs (10). The test suites caught 13. Four of the five that got through could not change any output: a field that is always overwritten, a guard repeated by the next line, a day-of-month the code drops anyway, and a Math.max whose other arm always wins. The fifth was a real gap. rrule-explainer never tested its warning that RFC 5545 forbids an ordinal BYDAY (like 1MO) alongside BYWEEKNO in a yearly rule. That test is in now. The catch rate on faults that could change an answer went from 13 of 14 to 14 of 14.

All writing · More in Testing and red team · All tools and research