My rails app does math incorrectly. I think this has something to do with variable types (int vs float), but not sure what is wrong.
The root problem is the method in my Stat model:
def lean_mass
self.weight * 0.01 * (100 - self.body_fat)
end
Where
Stat.weight = 140
Stat.body_fat = 15
it returns 119.00000000000001instead 119.
However where
Stat.weight = 210
Stat.body_fat = 15
it returns the 178.5correct number.
Does anyone know why he throws this small decimal digit?
The data type for weight is an integer, and body_fat is decimal if that helps.
source
share