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

If at least one of the operands is a float, the result will be a float too.

5 / 2.0 # => 2.5

In ruby, you create a float by specifying a decimal point:

2 #=> integer
2.0 #=> float

If you divide an integer by another integer, you get an integer. You have to use a float in the division:

5 / 2   #=> 2
5.0 / 2 #=> 2.5
5 / 2.0 #=> 2.5