MySQL “greater than” condition sometimes returns row with equal value
I’m running into a baffling issue with a basic MySQL query.
I’m running into a baffling issue with a basic MySQL query.
So, I am planning to make an application (PHP/MySQL) which deals a lot with money, and I am thinking about how to store and operate with the money, referring to PHP float data type and MySQL decimal.
Use round($result, 2)
on the result to round it to 2 decimal places.
Just for fun and because it was really easy, I’ve written a short program to generate Grafting numbers, but because of floating point precision issues it’s not finding some of the larger examples.
>>> float(str(0.65000000000000002)) 0.65000000000000002 >>> float(str(0.47000000000000003)) 0.46999999999999997 ??? What is going on here? How do I convert 0.47000000000000003 to string and the resultant value back to float? I am using Python 2.5.4 on Windows. Answers: Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the … Read more
I encountered negative zero in output from python; it’s created for example as follows:
I know that most decimals don’t have an exact floating point representation (Is floating point math broken?).
Python now uses David Gay’s algorithm for finding the shortest floating point representation that doesn’t change its value. This should help mitigate some of the confusion surrounding binary floating point numbers.