For example:
9 / 5 #=> 1
but I expected 1.8
. How can I get the correct decimal (non-integer) result? Why is it returning <
You can include the ruby mathn
module.
require 'mathn'
This way, you are going to be able to make the division normally.
1/2 #=> (1/2)
(1/2) ** 3 #=> (1/8)
1/3*3 #=> 1
Math.sin(1/2) #=> 0.479425538604203
This way, you get exact division (class Rational) until you decide to apply an operation that cannot be expressed as a rational, for example Math.sin
.