Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to parse money in Euro #95

Closed
crbelaus opened this issue Feb 12, 2019 · 2 comments
Closed

Unable to parse money in Euro #95

crbelaus opened this issue Feb 12, 2019 · 2 comments

Comments

@crbelaus
Copy link

I am trying to save a money field from a Phoenix input. Everything works properly except for the validation when I use Euros.

I've traced the problem to the Money.parse function.

iex(1)> Money.parse("99.99$")
#Money<:USD, 99.99>
iex(2)> Money.parse("99.99€")
{:error,
 {Money.Invalid,
  "Unable to create money from <<130, 172>> and <<57, 57, 46, 57, 57, 226>>"}}

It looks that the symbol is correctly associated with the EUR currency:

iex(3)> {:ok, currencies} = Cldr.Currency.currency_strings "en", Money.Cldr
{:ok, %{...}}
iex(4)> currencies["€"]
:EUR
iex(5)> currencies["$"]
:USD

It may be some trouble with the regular expression that splits the amount and the currency, since as you can see in the first error, it is interpreting the as <<130, 172>>.

@kipcole9
Copy link
Owner

kipcole9 commented Feb 12, 2019

Apologies for the inconvenience and thanks for the report. I have fixed on master and published version 3.2.3 to hex.

The issue was that I wasn't setting the :unicode flag on the regex used to parse the currency string (pretty much as you suspected). I've added a test for this particular case.

@crbelaus
Copy link
Author

Wow, that is an incredibly fast fix.

Thank you for your fast response and for such a wonderful package!! 🙌

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

No branches or pull requests

2 participants