Rails precision error
- by dontangg
When I run this in my Rails application:
my_envelope.transactions.sum(:amount)
This SQL is shown in the log files:
SQL (0.3ms) SELECT SUM("transactions"."amount") AS sum_id FROM "transactions" WHERE (envelope_id = 834498537)
And this value is returned:
<BigDecimal:1011be570,'0.2515999999 9999997E2',27(27)>
As you can see, the value is 25.159999. It should be 25.16. When I run the same SQL on the database myself, the correct value is returned.
I'm a little confused because I know that there are precision problems with Floats, but it is returning a BigDecimal. The SQL column type is decimal. Any ideas?