Reputation: 1018
I am entering '35444650.00' as a float into my MySQL and it keeps reformatting to 35444648.00, any help welcome...
Upvotes: 4
Views: 4430
Reputation: 1382
The MySQL manual claims that FLOAT, REAL, and DOUBLE PRECISION
fields stores values as approximate and INTEGER, SMALLINT, DECIMAL, and NUMERIC
fields stores values as exact.
I think best bet to overcome this precision issue is to use decimal.
Reference: http://dev.mysql.com/doc/refman/5.1/en/numeric-types.html
Upvotes: 4
Reputation: 272066
A higher precision alternative to float is DOUBLE
. But looking at the example, I think the DECIMAL
datatype might come in handy if the number of digits required after zero is small (around 2-4) and the number of digits before decimal is also small (around 10-12).
Upvotes: 2
Reputation: 21175
A float has 6 digits of precision. Use a double to get 15 or switch to a numeric(x,y). If you're interested, check out the storage requirements for MySQL for the different data types.
Upvotes: 4
Reputation: 2457
You are going past the level of precision possible. You need to define the float with more precision, i.e. "FLOAT(10,5)" would mean a float that can have 10 digits total with up to five after the decimal point.
Upvotes: 0
Reputation: 8040
Floats only have a certain level of precision, you may be going beyond how precise a float data type can be. Try using a DOUBLE instead.
Upvotes: 8