Related Articles

Related Articles

Ruby | Numeric to_int() function
  • Last Updated : 06 Jan, 2020

The to_int() is an inbuilt method in Ruby returns the integer part of the given number.

Syntax: num.to_int()

Parameters: The function needs the number whose integer part is to be returned.

Return Value: It returns the integer part.

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for to_int()
# method in Numeric
  
# Initialize a number 
num1 = 15.778
  
# Prints the integer part
puts num1.to_int()

chevron_right


Output:

15

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for to_int()
# method in Numeric
  
# Initialize a number 
num1 = -19.86
  
# Prints the integer part
puts num1.to_int()

chevron_right


Output:

-19
My Personal Notes arrow_drop_up
Recommended Articles
Page :