For my current project, I've had to redesign our old database and retain all of the old data. I wrote a rake task to copy all of the data (it's not a direct one-to-one mapping) which is working fine except for a few float values.
Some of the values are defined as floats in the old Mysql database. The issue is that my ActiveRecord queries are returning a rounded value instead of the actual value. If I run a query on the old database, I get:
mysql> select mean, format(mean, 10) from example_table;
+---------+------------------+
| mean | format(mean, 10) |
+---------+------------------+
| 1.10844 | 1.1084357500 |
| 1.10223 | 1.1022269726 |
| 1.11771 | 1.1177104712 |
+---------+------------------+
The actual values of mean match the formatted value MOST of the time. Occasionally, some values have fewer significant digits and the format(mean, 10) will provide incorrect digits (e.g. 1.1 will give something like 1.1000001421).
In my rake task, I query the old database with:
values = ActiveRecord::Base.connection.execute('SELECT mean FROM example_table')
Unfortunately, values will contain that rounded value instead of the actual value. Is there a way to get the actual value stored instead of the rounded value?
I'm using Mysql Distrib 5.1.51 and Rails 3.0.9
Clarification:
The problem isn't with the new database precision. The problem occurs before I ever try to save the data.
values = ActiveRecord::Base.connection.execute('SELECT mean FROM example_table') #selects from the legacy database
Using that line, each mean that is returned is rounded by the time I have access to it. I have not done anything with the new database at this point so it shouldn't have anything to do with this.
In other words, when I query mysql, I want it to return the exact value that was inserted. That may have been 1.0 or 1.23456789. I don't care how many significant digits, I just want that exact value.
Somewhere between executing my select statement and AR returning the values, the values are rounded. I'm trying to understand where that point is.