Repository navigation
fix(import): read 1,150 as 1150, not 1.15 - #333
Open
jayhemnani9910 wants to merge 1 commit into
Open
jayhemnani9910 wants to merge 1 commit into
jayhemnani9910 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A spreadsheet import saves a value written with a thousands separator about 1000 times too low:
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.
parseNumberinnutrition-import/common.jssays it handles1,5but not1,500, but its check (one comma and ^\d+,\d+) matches both and turns the comma into a decimal point.1,250.5gives 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,5and12,25are still decimal commas.Added
scripts/nutrition-import-numbers.test.js; the thousands case fails without the change.node --test scripts/*.test.jsshows the same 18 failures with and without the change (1410 passed with it).