Your float values are working correctly. It is important to understand when to use a float and when to use a decimal type field. In your situation, using a decimal field seems to be the best solution. Check out these two wiki pages which break down how you would use these in Drupal.
Float
Floating point is something that confuses a lot of people. Floating point numbers are essentially numbers stored in scientific notation, almost the same thing that we learned in math class in school...Floats and Doubles are used to store estimated values. The numbers they store can only be accurate to a certain precision.
Decimal (Numeric)
It allows you to specify the precision and scale of a number...use DECIMAL data type to store exact numeric values, where we do not want any rounding off, but exact and accurate values.
How to convert the field
In order to accomplish this you will need to create a simple module and activate it in Drupal. Start off by following steps 1-4 of this Drupal wiki page. After that is done, follow these steps:
- Copy the new ****.module file you created in steps 3-4 and change the extension to ****.install so you now have two files, both with just
<?php
at the beginning.
- Inside of the ****.install file, you need to add an update function that Drupal can run.
- Once you have that function, you would place the code from this answer inside.
- You will want to adjust the variables in the script to match your configuration ie;
$field
, precision
, scale
, not null
.
- Backup your database, and be ready to revert back to the backup if things go wrong.
- Activate the new module, which I suggest you do from the command line via
drush en your_module_name
.
If your website is not too large, you can get away with this, but if it is big, you will have to explore your options because eventually PHP will timeout.