对每位程序员来说,在编程过程中数据处理是不可避免的,很多时候都需要根据需求把获取到的数据进行处理,取整则是最基本的数据处理。取整的方式则包括向下取整、四舍五入、向上取整等等
-
向下取整:int()
-
四舍五入:round()
-
可以理解成向下取整:math.floor()
-
向上取整:math.ceil()
from math import floor, ceil
num = 5.99
print(int(num))
print(round(num))
print(floor(num))
print(ceil(num))
#Python学习交流QQ群:725638078
num = 5.49
print(int(num))
print(round(num))
print(floor(num))
print(ceil(num))
print(type(round(num)))
print(type(floor(num)))
print(type(ceil(num)))
- 输出
5
6
5
6
5
5
5
6
<class 'int'>
<class 'int'>
<class 'int'>
标签:floor,Python,ceil,num,取整,print,round
From: https://www.cnblogs.com/chentiao/p/16664012.html