Skip to content

fix(scalars): parse USCurrency amounts with multiple thousands separators#3087

Open
ifeanyi-ugwu wants to merge 1 commit into
graphql-hive:masterfrom
ifeanyi-ugwu:fix/uscurrency-comma-parsing
Open

fix(scalars): parse USCurrency amounts with multiple thousands separators#3087
ifeanyi-ugwu wants to merge 1 commit into
graphql-hive:masterfrom
ifeanyi-ugwu:fix/uscurrency-comma-parsing

Conversation

@ifeanyi-ugwu

Copy link
Copy Markdown
Contributor

generateCents stripped only the first thousands separator (.replace(',', '')), so an amount with more than one separator parsed to the wrong value — e.g. $1,000,000.00 parsed as $1,000.00, because parseFloat stops at the second comma. It now removes every separator (.replace(/,/g, '')).

Adds a regression test ($1,000,000.00100000000 cents) that fails without the fix. The existing tests only used single-separator amounts ($22,900.00), which the one-comma replace happened to handle.

…tors

generateCents stripped only the first comma, so a value like $1,000,000.00
parsed as $1,000.00 — parseFloat stopped at the second separator and dropped
the rest. It now removes every separator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant