Check for equality on a MySQL Float field

后端 未结 5 1578
失恋的感觉
失恋的感觉 2021-02-12 16:00

I have a Joomla system and I\'m trying to change the search so that it correctly finds floating point values in the database.

So, I have a query that is built at runtime

5条回答
  •  梦毁少年i
    2021-02-12 16:36

    Usually with these types of questions it's good to provide a small example to replicate your results.

    Usually testing for exact float values is a bad idea since floating point precision isn't an exact science. It's much better to use some tolerance.

    create table foo1 (col1 float);
    
    insert into foo1 values (2.18);
    select * from foo1 where abs(col1-2.18) <= 1e-6
    

提交回复
热议问题