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 :
puts "coerce example 1 : #{2.5.coerce(1.1)}\n\n"
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 :
puts "coerce example 1 : #{2.00.coerce(1.1)}\n\n"
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]
Last Updated :
08 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...