Home >Backend Development >Python Tutorial >How to use floor in python

How to use floor in python

藏色散人
藏色散人Original
2019-06-22 13:39:484633browse

How to use floor in python

python floor() returns the rounded down integer of a number.

The following is the syntax of the floor() method:

import math
math.floor( x )

Note: floor() cannot be accessed directly. You need to import the math module and call the method through a static object. .

Parameters

x -- Numeric expression.

Return value

Returns the rounded integer of the number.

The following shows an example of using the floor() method:

#!/usr/bin/python
import math   # This will import math module
print "math.floor(-45.17) : ", math.floor(-45.17)
print "math.floor(100.12) : ", math.floor(100.12)
print "math.floor(100.72) : ", math.floor(100.72)
print "math.floor(119L) : ", math.floor(119L)
print "math.floor(math.pi) : ", math.floor(math.pi)

The output result after running the above example is:

math.floor(-45.17) :  -46.0
math.floor(100.12) :  100.0
math.floor(100.72) :  100.0
math.floor(119L) :  119.0
math.floor(math.pi) :  3.0

Related recommendations: "Python Tutorial

The above is the detailed content of How to use floor in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to make gif in pythonNext article:How to make gif in python