Skip to content


Subversion checkout URL

You can clone with
Download ZIP


ActiveRecord float behavior changed from Rails 3.0 -> 3.1? #4549

jakedouglas opened this Issue · 8 comments

4 participants


I have an application on Rails 3.0.3 accessing a legacy MySQL database with a float column. It appears that upgrading to Rails 3.1.3 causes some values of this column to be interpreted differently. I am using REE 1.8.7 2011.03 and the mysql 2.8.1 gem. I don't see anything obvious changing in my Gemfile.lock that could be responsible for this (for instance, using a different version of the mysql adapter).

Rails 3.0.3

ree-1.8.7-2011.03 :025 > OrderCardItem.find(72788).rods_sort
=> 0.01

Rails 3.1.3

ree-1.8.7-2011.03 :001 > OrderCardItem.find(72788).rods_sort
=> 0.00999999977648258

I understand that there are a lot of idiosyncrasies inherent in floating point representation, but this is reproducible and looks like the result of some change between these version of Rails. I've looked through the git history and haven't been able to find anything.

Any help appreciated...thanks.


Can you select this row via the mysql command line interface and paste the output? I believe it's due to a difference between how mysql rounds floats and how ruby rounds floats.


mysql> select rods_sort from order_card_items where id = 72788;
| rods_sort |
| 0.01 |


We have the same problem in our apps just migrated to rails 3.1
Did you find the solution?


Using mysql2 adapter everything works fine again. :)


This still doesn't explain why the behavior changed...


Looks like this is a problem in the mysql driver:

require 'mysql'

class Mysql
  class Stmt; include Enumerable end
  class Result; include Enumerable end

mysql = Mysql.init
mysql.real_connect 'localhost', 'root', '', 'testing', nil, nil, nil

mysql.query <<-eotable
  (fun_column float)

mysql.query 'delete from tests'
mysql.query 'insert into tests (fun_column) values (0.1)'

result = mysql.query 'select fun_column from tests'
p Float(result.to_a.first.first)

stmt = mysql.prepare 'select fun_column from tests'
result = stmt.execute
p Float(stmt.to_a.first.first)
@tenderlove tenderlove closed this

So I guess you aren't concerned at all with why this behavior changed from one version of Rails to another?


Hi tender,
Same Mysql driver is working fine with Rails3.0.10 but fails in 3.1.12, How can i get rid of it.

Srijith C

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.