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

Ashley Moran ashley.moran at patchspace.co.uk
Sun Nov 9 07:27:23 EST 2008

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  


[1] http://www.theregister.co.uk/2006/08/12/floating_point_approximation/


More information about the rspec-users mailing list