to_money not working as expected when precision is skipped?
Hi Guys,
We are using money gem. Version 6.7.1
I have noticed a difference in how #to_money works with or without precision
"1.000,00".to_money("CRC").to_s
=> "1000.00"
vs
"1.000".to_money("CRC").to_s
=> "1.00"
Isn't this wrong?
The issue might be because "CRC" has a dot "." as the thousand separator and comma "," as decimal mark
NOTE: I am willing to raise a PR if this is an issue. Just let me know what to do.
@rajdeep26 looks like an actual issue, I'm happy to merge your PR with a fix. It seems like the issue is in the monetize gem, which provides #to_money method for the core classes.
Thanks for confirming that. I will try to raise a PR for this.
@antstorm I was just going through the code and found a flag in the Monetize class called enforce_currency_delimiters.
This is what is documentation above that variable says
Monetize uses the delimiters set in the currency to separate integers from decimals, and to ignore thousands separators. In some corner cases, though, it will try to determine the correct separator by itself. Set this to true to enforce the delimiters set in the currency all the time.
I tried setting it to true and it gave correct results.
Monetize.enforce_currency_delimiters = true
=> true
"1.000".to_money("CRC").to_s
=> "1000.00"
@rajdeep26 - this issue appears like it has been solved and a workaround has been identified. Close this issue?
Yes. Sure.
Thanks for all the help.