I am converting Celsius into Fahrenheit using the code below, however the exact result I require is slightly different from the one I am getting, simply because I put the float division within brackets. My question is, why is this the case?
def convertToCelsius(temp)
celsius = (temp.to_f - 32) * 5.0 / 9.0 # => -29.444444444444443
return celsius # => -29.444444444444443
end # => :convertToCelsius
convertToCelsius(-21) # => -29.444444444444443
(See below the slight difference in result).
def convertToCelsius(temp)
celsius = (temp.to_f - 32) * (5.0 / 9.0) # => -29.444444444444446
return celsius # => -29.444444444444446
end # => :convertToCelsius
convertToCelsius(-21) # => -29.444444444444446