Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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
like image 590
mewosic Avatar asked Mar 19 '26 10:03

mewosic


1 Answers

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

5 / 2.0 # => 2.5
like image 59
Sergio Tulentsev Avatar answered Mar 21 '26 09:03

Sergio Tulentsev