Closed teamon closed 1 year ago
I've been running into similar problems when trying to use custom currencies with decimal values larger than 15. With Ethereum for example, the amount of precision seems to drastically drop when compared to a currency that requires fewer decimals. If I had to guess, like you mentioned it comes back to the Float.parse
call because precision is really problematic when dealing with float to money conversions especially.
I have a similar issue, basically I need to get the percentage of an amount but the percentage is decimal, i.e
iex> 100 * 0.125
12.5
iex> Money.new(100, :USD) |> Money.multiply(0.125)
%Money{amount: 13, currency: :USD}
I'm not sure if it should return %Money{amount: 1250, currency: :USD}
instead of %Money{amount: 13, currency: :USD}
While migrating an app from
integer
tobigint
db types I've noticed that Money does not handle big values properly:The problem seems to be coming from the usage of
Float.parse/1
Would it make sense to parse with
Decimal.parse
? Optionally if the decimal dependency is not available fallback to manual parsing of left & right sides of decimal point and combining using only integers.