Using Microsoft SQL Server 2008. I have a table of interest rates. I’ve manually verified that the data I’m trying to select does exist in the table.
This returns records:
SELECT *
FROM [MyTable]
WHERE [Rate]=3.99/100
This does not return records:
SELECT *
FROM [MyTable]
WHERE [Rate]*100=3.99
Here’s the really messed up part: As far as I can tell, this only happens when the Rate field contains a value of .035, .03625, or .0399.
Can anyone tell me why the second instance does not work? This table does have an ID field (PK), and the Rate field is FLOAT. Please let me know if you need any more info.
You should use decimal not floats for interest rates.
floatis imprecise and you encounter rounding errors as you have discovered!On my machine
Returns
Obligatory Link: What Every Computer Scientist Should Know About Floating-Point Arithmetic