Reputation: 11
when i'm trying to sum numbers into one variable from mysql query (the field type is double without format) with php it give me a not normal result.
let say i got few row from query, first row 0.54 and 2nd row 0.2, etc. in the end the result should be 2.433 if i sum all rows manually.
but when i echo the variable shown as this >> 2.433000000000000273558953267638571560382843017578125
where is the rest number come from? and how to prevent it come without use round or format it? or did i miss something?
Edit : I have try to change it to decimal 15,4 but it still sum is as before like this 2.433000000000000273558953267638571560382843017578125 and the wierd thing is the number shown as normally and change after count on php for function.
Upvotes: 1
Views: 40
Reputation: 1790
If you need to make maths calculations on those values, you should consider using DECIMAL instead of DOUBLE or FLOAT in MysQL.
Take a look here : difference between float and decimal data type
Upvotes: 1