I am using mySQL
and CodeIgniter
. I have some floating point numbers in my database such as
Assuming that you have a 10% tolerance (+/-) you could try something like:
select * from table
where value >= ($myvalue * .9) and value <= ($myvalue * 1.1)
order by abs(value - $myvalue) limit 1
Slightly updated stealing from others - this should return the nearest result in the assumed tolerance range. (Also, I just noticed the where was incorrect, apologies - now it should work).