Selecting a float in MySQL

后端 未结 8 2043
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 08:35

I am trying to do a SELECT match on a table based upon an identifier and a price, such as:

SELECT * FROM `table` WHERE `ident`=\'ident23\' AND `         


        
相关标签:
8条回答
  • 2020-11-29 08:52

    Perhaps something along these lines:

    SELECT * FROM table WHERE ident='ident23' AND ABS(price - 101.31) < .01;
    
    0 讨论(0)
  • 2020-11-29 08:54

    It doesn't work because a float is inherently imprecise. The actual value is probably something like '101.3100000000001' You could use ROUND() on it first to round it to 2 places, or better yet use a DECIMAL type instead of a float.

    0 讨论(0)
提交回复
热议问题