Posts [ 4 ]

Topic: ActiveRecord Float precision? How to represent $10 000.12

Hi Guys

I just viewed some weird behaviour. I have a model which includes a float. It seems that the precision of a floating point record is not very good. Pathetic actually. I use the model to keep track of money (mostly), and it loses precision pretty quickly: Check it:

Re: ActiveRecord Float precision? How to represent $10 000.12

Check Rails AP, ActiveRecord::ConnectionAdapters::TableDefinition and look for 'precision' option in 'column' method, as it depends on the DB you use.Normally, you define the precision in your migration file, something like this: