Skip to content

fix(import): read 1,150 as 1150, not 1.15 - #333

Open
jayhemnani9910 wants to merge 1 commit into
TraceApps:devfrom
jayhemnani9910:fix/import-thousands-separator
Open

jayhemnani9910 wants to merge 1 commit into
TraceApps:devfrom
jayhemnani9910:fix/import-thousands-separator

Conversation

@jayhemnani9910

Copy link
Copy Markdown

A spreadsheet import saves a value written with a thousands separator about 1000 times too low:

Date,Meal,Name,Calories,Protein (g),Sodium (mg)
2026-11-01,Dinner,Pizza,"1,150",48,"2,300"

Pizza is stored with 1.15 kcal and 2.3 mg sodium, and the import reports no error. Google Sheets and Excel write the displayed value into the CSV, so any column with a thousands format looks like this.

parseNumber in nutrition-import/common.js says it handles 1,5 but not 1,500, but its check (one comma and ^\d+,\d+) matches both and turns the comma into a decimal point. 1,250.5 gives 1, because the comma stops the number regex.

A comma followed by groups of exactly three digits (1,150, 12,000, 1,250.5) is now read as a thousands separator. 1,5 and 12,25 are still decimal commas.

Added scripts/nutrition-import-numbers.test.js; the thousands case fails without the change. node --test scripts/*.test.js shows the same 18 failures with and without the change (1410 passed with it).

parseNumber turned the comma of any single-comma number into a decimal point,
although its comment says 1,500 is a thousands separator. A spreadsheet export
with a thousands format writes the displayed value, so a 1,150 kcal dinner was
saved as 1.15 kcal. A comma before groups of three digits now separates
thousands; 1,5 is still a decimal comma.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant