floating point - Check for equality on a MySQL Float field -


I have a Joomla system and I am trying to change the search so that it fixes the temporary point values ​​in the database properly Finds

So, I have a query that was created on runtime that looks like this:

  Select 'column_8' from 'some_table' where 'some_float_field' & Lt; = & Gt; '2.18' This does not work, it does not match anything at all, even though I see records in DB with this value.  

Do this instead:

  Choose 'column1' from 'some_table' where 'some_float_field' & lt; = & Gt; 2.18  

There is no luck, so I tried casting a decimal (float does not work for some reason), so I tried to do it:

< Pre> select 'Some_table' to 'column1' where 'some_float_field' & lt; = & Gt; CAST ('2.18' AS DECIMAL (20, 2))

There is no dice ...

Keep in mind that> = or & lt; = Gives fair results, just & lt; => Gives me problems

How do I get the similarities to work here?

It is usually good to provide a short example to repeat your results with these types of questions .

Usually testing exact float values ​​is a bad idea because the floating point is not accurate precision science. It is better to use some tolerance.

  create table foo1 (col1 float); Insert Foo1 values ​​(2.18); Choose from FU1 * where stomach (col1-2.18) & lt; = 1e-6  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -