Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
math
floor
communitycreator

What is floor() in Ruby?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

The floor() function in Python returns the next largest number less than or equal to a number set as a parameter. Figure 1 below shows the mathematical representation of the floor() function.

Figure 1: Mathematical representation of floor() function

Syntax

num.floor(digits)
## where num is a number to round down

Parameter

This function requires n digits to which the precision of decimal digits is kept. It is optional, and if its value is omitted, then its default value is 0.

1.234567.floor(2)   => 1.23
34577.78.floor(-2)  => 34500 

Return value

The floor() function returns the next largest number less than or equal to the number set as a parameter.

Example

#positive integer
num1=10
print "num1.floor() : ", num1.floor(), "\n"
#negative integer
num2=-10
print "num2.floor() : ", num2.floor(), "\n"
#positive float value
num3=2.1
print "num3.floor() : ", num3.floor(), "\n"
#negative float value
num4=-2.1
print "num4.floor() : ", num4.floor(), "\n"

RELATED TAGS

python
math
floor
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring