On Nov 08, 2008, at 2:18 am, Zach Dennis wrote:

<[EMAIL PROTECTED]> 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
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to