linzilan linzilan - 6 months ago 13
Ruby Question

how to initialize a variable to the type "double" in ruby

like in C and C++

double x


How to do it in ruby ?

Or to be in the type float?

I want to run

x=5/2


then

x=2.5


instead of

x=2

Answer

If one operands is float, result will be float too.

5 / 2.0 # => 2.5