Repository navigation
A minus sign before the currency reads as negative, so "-$5 million" is -5000000 instead of no value - #1435
Open
rudycelekli wants to merge 1 commit into
Open
A minus sign before the currency reads as negative, so "-$5 million" is -5000000 instead of no value#1435rudycelekli wants to merge 1 commit into
rudycelekli wants to merge 1 commit into
Conversation
…is -5000000 instead of no value Signed-off-by: Rudy Celekli <rudy@gradiahq.com>
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.
Why
scan_quantityreads a currency symbol at the very start of the text, then the number with its sign. A loss or a negative balance is usually written with the minus in front of the symbol: "-$5 million", "−€30 million", "-$1,250". There the first character is-, so no currency is found, the number scan stops at$, and the value is not read at all. The same figure written "$-5 million" reads as -5000000.So a net loss stated as "-$5 million" under a number attribute stays out of the typed graph, and
literal_objectdoes not see it as a value either.What changes
If the text starts with
-or the typeset−and the next character is a currency symbol, the sign is set aside, the currency is read as before, and the sign goes back on the number before it is parsed (so a magnitude word still scales the signed value). A dash that is not followed by a currency symbol is left alone, so "- 5" is still not a number, and a double sign ("-$-5") is still no value.How it was checked
a_minus_sign_before_the_currency_is_read_as_negative, covers "-$5 million", "−€30 million", "-$1,250", "-£0.5", "-¥2.3亿" under 万元, "- 5" and "-$-5".left: None right: Some(Number(-5000000.0)).cargo test -p utopia-extract --lib: 113 passed.cargo fmt -p utopia-extract --checkandcargo clippy -p utopia-extract --all-targets -- -D warningspass.Before review
git commit -s)cargo fmt --all --check,cargo clippyandcargo testpass for the touched crate