My application deals a lot with money. I'm currently using BigDecimal
(SQL decimal) to represent money, which is kind of a hassle because of
all the BigDecimal.new('...') calls. For this reason, I'm considering
switching over to float. Is there any reason not to do so?
If you’ve used a decimal datatype [with the necessary precision and scope options] in your db, Rails should be able to handle managing the decimal part for you. You might still need to use number_to_currency and formatting in your views but AFAIK Rails is able to handle the conversions on its own and save you the work.
zomg rsl posts on the rubyonrails-talk mailing list!
Anyway,
For money I use a single integer field, sometimes cost_in_cents, and then use the Money gem to parse that to a real format. Thankfully I haven’t yet to deal with fractions of a cent. If you’re not worried about fractions of a cent, then go for the Money gem and an integer field.
i haven’t worked with currency a lot myself. what are the benefits of using the money gem over decimal datatype? or just another tool? i’ve seen it touted before and wondered. no place like the mailing list to get some perspectives.
Well, my use of money gem and integer for currency amounts stems from
the fact that the ActiveMerchant plugin works with those. Over time,
though, I've found it to be a very dev-friendly solution.
I'm not sure if I can come up with an overriding, grand reason for using
one or the other, tbh.