Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Ruby Float coerce() method with example

  • Last Updated : 08 Jan, 2020

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]
My Personal Notes arrow_drop_up
Recommended Articles
Page :