MySQL: Comparing float / double
Posted by mkhairul - October 30, 2009 at 02:10:56 am - No CommentsCategories: Development, Tips
I have not done a lot of raw SQL for quite a while. In my current job, I need to do it. Since we’re using MySQL 4, my options were quite limited as I have to be wary about any features to a specific version (especially > 5).
So I was trying to find how to exclude the amount 0.00 from the result. The obvious one would be
foo.value > 0.00
But the comparison is not precise (I googled a bunch of links, but now they’re gone, you can try to google “mysql float comparison”), I would leave the detailed explanation for you to find out.
The way that I found that fullfills the result that I need is,
ROUND(foo.value, 2) > ROUND(0, 2)
No Comments yet »
RSS feed for comments on this post. TrackBack URI
Leave a comment
GimpStyle Theme design by Horacio Bella.
