[rspec-users] any tricks re using " eql(5.5)", but where 5.5 is a decimal not float?

Greg Hauptmann greg.hauptmann.ruby at gmail.com
Sun Nov 9 19:21:19 EST 2008

Ashley - what's you're recommendation re using BigDecimal (which does
work as you point out) and the Money gem (which it sounds like makes a
dev's life a bit easier)???  Is it worth trying to port an application
from use of BigDecimal to Money gem???

On Sun, Nov 9, 2008 at 10:27 PM, Ashley Moran
<ashley.moran at patchspace.co.uk> wrote:
> On Nov 08, 2008, at 2:18 am, Zach Dennis wrote:
>> <greg.hauptmann.ruby at gmail.com> wrote:
>>> yep - this was recommended on forums over float - why?
>> You are in for a lot of headaches in you application resorting to
>> decimal fields in the database, since it restores them as BigDecimals.
>> It sucks to deal with BigDecimals in your app. I very highly recommend
>> the Money library. I recommend installing it as a plugin and using the
>> CollectiveIdea fork.
> Ha, I wrote the ActiveRecord patch so this was possible :)
> The reason for storing monetary values as SQL decimals is that they aren't
> subject to rounding errors[1].  I used to work in the finance sector, and it
> was absolutely unacceptable to expose financial calculations to these
> errors.  Hence I added support in ActiveRecord so we could use Rails; it was
> just not an option otherwise.
> The decision you have to make is between the extra effort now of using
> decimals in your code vs the extra effort later of explaining to your users
> why your calculations sometimes come out wrong.  And that depends on how
> much your users value knowing that these figures are correct.
> Ashley
> [1] http://www.theregister.co.uk/2006/08/12/floating_point_approximation/
> --
> http://www.patchspace.co.uk/
> http://aviewfromafar.net/
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list