I have a string \"1/16\" I want to convert it to float and multiply it by 45. However, I dont get the desired results.
\"1/16\"
45
I am trying in
This is the most understandable answer I can think of:
def toFloat(fract) str = fract.to_s parts = str.split("/") numerator = parts[0].to_f denominator = parts[1].to_f return numerator / denominator end puts toFloat(3/4r) # 0.75 puts toFloat(2/3r) # 0.666666666666...