in reply to Filthy Floats
where $fv is the value to put in the query and $dv is the value from the database.$fv = sprintf("%1.2f", $dv);
What that really does is use decimal representation and string conversion to set the accuracy of the floating point value. It's equivalent to querying the database for matches to a given level of accuracy:
For some reason, the comparison version bothers a lot of programmers, where chopping off digits in a string representation doesn't.SELECT * FROM table WHERE abs(float - 0.98) < 0.001;
|
---|