mysql和php浮点数据类型

In my app i want save float or double values that are calculated using php into mysql. I also want to make calculations with these columns in stored procedures using sql. But i notice that double and float data types show different in php and mysql. for example after a calculation in php i might get a value 4.00 while the same calculation is mysql is 4.0027. How can i make possible to have more or less the same value calclated. what type should my columns in mysql be and what cast should i make in php? Thanx

You may read this page for answers why sum of two integers often results in a float.

Considering the MySQL data type, the difference is discussed and explained in this question: Difference between float and decimal data type

I would suggest to store in decimal with some rounding before insert/update in PHP.

Again, everything depends on the calculations you perform on the values.

Try this

use number_format("4.0024",2); output 4.00

or Update

use number_format("6556564.0024",2, '.', ''); or number_format(6556564.0024,2, '.', ''); output 6556564.00