@katie You can’t use floats for money because 2.3 - 0.3 = 1.99999999999 in floating point logic

“Decimal” types solve this by storing the value as integers internally

Using integers directly works when you also store the currency, and keep a table of the currency’s exponent, eg https://github.com/elixirmoney/money/blob/master/lib/money/currency.ex

I prefer this way because then I don’t have to worry about the database representation, or what happens to the value in a JSON API.

Follow

@alex @katie@mstdn.io
I am sorry, but you really cannot buy a 2 dollar razor for 1.999999997 dollars. :angry_gun:

Sign in to participate in the conversation
Game Liberty Mastodon

Mainly gaming/nerd instance for people who value free speech. Everyone is welcome.