The to_i
method returns a float that is truncated to an integer. This means that it converts a float value to an integer.
Note: The
to_int
method can also achieve this.
float_value.to_i
float_value
: This is the float value that invokes the method. It is this float value we want to convert to an integer.
The to_i
method returns an integer.
# create float valuesf1 = 1.2f2 = 100.224f3 = 0.3f4 = 23.333# convert to integer# and print resultsputs f1.to_iputs f2.to_iputs f3.to_iputs f4.to_i
f1
, f2
, f3
, and f4
.to_i
method on the float values we created and print the results to the console.