Returning currency without price
See original GitHub issueDoes it makes sense to return a Price instance with currency set and without a price value?
Actually if we have a substring inside a string that matches with an existing currency, it will be returned even if we are not mentioning the currency:
In [1]: Price.fromstring("STRING WITH NO PRICE BUT HAS A WORD THAT CONTAINS PART OF A CURRENCY NAME: EUROPE")
Out[1]: Price(amount=None, currency='EUR')
This happens because we use regexes to match the currencies inside a string. But this approach would create a problem when single-letter currencies is handled better (#3) .
I can see two options to handle this scenario:
- Consider as currency only if the substring is surrounded by whitespaces:
In [2]: Price.fromstring("SOMETHING EUROPE SOMETHING")
Out[2]: Price(amount=None, currency=None)
In [3]: Price.fromstring("SOMETHING EUR SOMETHING")
Out[3]: Price(amount=None, currency='EUR')
- Consider as currency only if the entire string matches exactly with the currency name:
In [4]: Price.fromstring("EUR")
Out[4]: Price(amount=None, currency='EUR')
In [5]: Price.fromstring("SOMETHING EUR SOMETHING")
Out[5]: Price(amount=None, currency=None)
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Where to Exchange Currency Without Paying High Fees
Trading currency at the hotel or even a currency kiosk in an airport or elsewhere in the country can be costly due to...
Read more >Foreign Exchange | Wells Fargo
Wells Fargo account holders can order foreign currency cash online, at a branch, or at 1-800-626-9430 and have delivery within 2-7 business days....
Read more >Placing A Foreign Currency Order FAQs - Bank of America
There is no fee for ordering foreign currency online. The bank receives compensation from the purchase and sale of foreign currency banknotes in...
Read more >Need to return the value with an Currency sign - Stack Overflow
3. double s cannot have currency signs. · After you get the price, convert it to a string and prepend the dollar sign....
Read more >Foreign Currency and Currency Exchange Rates - IRS
You must express the amounts you report on your U.S. tax return in U.S. dollars. ... If your functional currency is not the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think so.
When a real-life scenario comes up where this is troublesome, we can look into improvements to solve or mitigate such issues. For example, ignore specific currency expressions on specific locales (I assume we are getting locale support à la dateparser eventually), such as ignoring “R” on languages where “R” is a common word and they always use a different text when referring to the “R” currency.
I think option 1 is the way to go. We just need to improve the regular expressions that we use to match currencies so that “Europa” does not count as “EUR”.