convert variable from int to float in Ruby
Code snippet on how to convert variable from int to float in Ruby
int_var = 7
float_var = int_var.to_f
This code snippet shows how to convert a variable from an integer to a float in Ruby. First, a variable called int_var
is declared and assigned the integer value of 7. Then the to_f
method is used to convert the variable int_var
to a float, and the float is assigned to the variable float_var
. The to_f
method takes the integer value of int_var
and converts it to the same value as a float. After the conversion, float_var
now contains the float value of 7.0.