Money representation: float or BigDecimal?

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?

Eric

On 3 Jun 2008, at 22:47, Eric LIn wrote:

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?

There are millions of rounding-off reasons not to do so. Or use
integers and fixed point.

This is actually one of the areas where I severely miss the automatic
variable-precision handling of numbers in Smalltalk.

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.

Eric LIn wrote:

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?

Eric

The money gem and the rails_money plugin are great.

You put, say “cost_in_cents” in your model as an integer. Then you can
reference the “cost” method and it will return a money object, all the
while storing as an integer. cost.to_s returns a currency-formatted
string of the amount.

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.

RSL

On Tue, Jun 3, 2008 at 9:50 PM, Cayce B. <

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.

RSL ___ wrote:

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.

RSL

On Tue, Jun 3, 2008 at 9:50 PM, Cayce B. <

disclaimer needed - I haven’t worked with global currency issues and
thus need to wrap my comments with .

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.

RSL