I deal with interest rates in a mysql database. These are stored as a double and are generally to the thousandths decimal place (ex: 4.657) but sometimes more. Sometimes, I need to report on these only to the hundredths place (ex: 4.65) but I cannot round these- I need to have them truncated. So, if my interest rate in the database in 5.6575%, I need to get 5.65%, not 5.66%.
Generally speaking, TRUNCATE(int_rate, 2) will work just fine. This has worked for me with no issues until now.
I am having a problem with the following interest rates: 8.0300%, 8.0400%, 9.0300%, 9.0400%, 10.0300%, 10.0400%... etc. It is only when the interest rate is over 8% and 3 or 4 is in the hundredths place and the rest is 0s.
If 8.04 is in the DB, when I do TRUNCATE(int_rate, 2), it returns 8.03. It also does this if I try to use FLOOR: FLOOR(int_rate*100)/100
If I hard code the number and do not pull it from the DB, it truncates properly: TRUNCATE(8.04, 2) or TRUNCATE(8.0400, 2) returns 8.04, as expected.
4.0400% works just fine! So does 8.0600%! Why is it giving these results? Also, if anyone can suggest how to do this without this error, that would be phenomenal!
MySql: 5.0.95