Ruby Float coerce() method with example
coerce() is a float class method which return the ceil value of the passed float value.
Syntax: float.coerce()
Parameter: numeric values (can be integer as well as float value)
Return: An array with both float and numeric value represented in the form of Float objects.
Example #1 :
# Ruby code for coerce() method # ceil value of the float value puts "coerce example 1 : #{2.5.coerce(1.1)}\n\n" # ceil value of the float value puts "coerce example 2 : #{2.11115.coerce(22221)}\n\n" |
Output :
coerce example 1 : [1.1, 2.5] coerce example 2 : [22221.0, 2.11115]
Example #2 :
# Ruby code for coerce() method # ceil value of the float value puts "coerce example 1 : #{2.00.coerce(1.1)}\n\n" # ceil value of the float value puts "coerce example 2 : #{-333333.coerce(2.21)}\n\n" |
Output :
coerce example 1 : [1.1, 2.0] coerce example 2 : [2.21, -333333.0]
Please Login to comment...