# Ruby program to demonstrate the floor() function

Ruby Example: Write a program to demonstrate the floor() function.
Submitted by Nidhi, on December 11, 2021

Problem Solution:

In this program, we will create variables with some initial values. Then we will truncate the decimal value of given numbers using the floor() function.

Program/Source Code:

The source code to demonstrate the floor() function is given below. The given program is compiled and executed successfully.

```# Ruby program to demonstrate
# the floor() function

num1 =  10.23;
num2 = -20.53;

print "Num1: "  ,num1.floor();
print "\nNum2: ",num2.floor();
```

Output:

```Num1: 10
Num2: -21
```

Explanation:

In the above program, we created two variables num1, num2 initialized with 10.23, -20.53 respectively. Then we truncated the decimal value of given numbers using the floor() function and printed the result.

Preparation

What's New

Top Interview Coding Problems/Challenges!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates