Possible Duplicate:
Arithmetic in ruby
The status_update model takes 2 values in, does some simple calculations with them, and assigns 'current_lbm' and 'current_bf_pct' from there.
current_lbm and current_bf_pct will produce massive decimals if I don't restrain them so I used the .round(2) method to limit the values to 2 decimal places.
Here is the method that does this.
after_initialize :default_values
.
.
def default_values
if self.current_bf_pct >= 0.5
self.current_bf_pct /= 100
if self.current_bf_pct <= 0.04
self.current_fb_pct *= 100
end
end
self.current_fat_weight = self.current_weight * self.current_bf_pct
self.current_lbm = self.current_weight - self.current_fat_weight
self.current_fat_weight = self.current_fat_weight.round(2)
self.current_lbm = self.current_lbm.round(2)
end
Here are the results:
09/13/2012 186.0 4.5 177.63 8.37
09/13/2012 187.0 5.5 176.72 10.29
09/13/2012 188.0 6.5 175.78 12.22
09/13/2012 189.0 7.5 174.83 14.18
09/13/2012 190.0 8.5 173.85 16.15
09/13/2012 191.0 9.5 172.86 18.15
09/13/2012 192.0 10.5 171.84 20.16
09/13/2012 193.0 11.5 170.81 22.2
09/13/2012 194.0 12.5 169.75 24.25
09/13/2012 195.0 13.5 168.68 26.33
09/13/2012 196.0 14.499999999999998 167.58 28.42
09/13/2012 197.0 15.5 166.47 30.54
09/13/2012 198.0 16.5 165.33 32.67
09/13/2012 199.0 17.5 164.18 34.82
09/13/2012 200.0 18.5 163.0 37.0
my question is... what the heck is up with 14.499999999999998??
These are the results from the view. The current_bf_pct row is the 3rd one from the dates. They aren't decimals because I multiply them by 100 in the view.