Portal Home > Knowledgebase > Articles Database > mysql - dividing two columns of type double
Posted by ilyash, 09-06-2008, 07:46 PM Hey guys, I don't know if this is a mysql bug, but if you do something like select columna - (columnb/columnc) from table; where they are all double, if the value of b/c is very small you will just get a 0 for that division what would be the proper fix? like how do i tell it to keep it as a double and not convert to int? I tried doing 1.0000* [the above] and it works.. but there must be a better way
Posted by bigfan, 09-06-2008, 11:42 PM It's not a bug; problems computing with high-precision fractional numbers are historic and well-documented. You might consider storing them as decimal rather than double (esp. with MySQL 5.03+), or doing the operations on the fetched values with, for example, PHP's BCMath functions.
Add to Favourites Print this Article