I’m having problems with using Rails for a financial application: the
database stores financial fields as decimal, but ActiveRecord converts
these to float - so I get the rounding errors you’d expect
(Floating Point : Java Glossary).
This has come up recently, and the recommended fix seems to be to be
Tobi Luetke’s ‘money’ gem
(http://article.gmane.org/gmane.comp.lang.ruby.rails/46632/match=money+bigdecimal)
but this won’t work for me: I’ve inherited the (SQLServer) database, and
financial fields are defined as decimal: I can’t insist on changing
everything to integer values in cents.
What seems to be needed is changing the Ruby type mapping, which seems
to be a ‘good idea’ that’s come up before
(http://article.gmane.org/gmane.comp.lang.ruby.rails/713) but hasn’t
made it into Rails, at least not 1.0. Have people tried and given up?
What would be involved?
I’ve had a poke around abstract_adapter.rb and sqlserver_adapter.rb and
can see some places to hack, but haven’t followed through the
implications. I don’t mind adding a dependency on bigdecimal, even if
only the resulting fix could only be distributed as a plugin rather than
a patch to the Rails trunk.
Any help, hacks or workarounds much appreciated - if I can’t solve this
problem in Rails, my chances of selling Ruby and Rails internally more
or less vanish…
thanks
Stuart