Python 有三种方式取整:向下取整、向上取整、四舍五入。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author: wxnacy([email protected])
import math
# 向上取整
print(math.ceil(2.4)) ==> 3
# 向下取整
print(math.floor(2.8)) ==> 2
# 四舍五入
print(round(2.8)) ==> 3
print(round(2.2)) ==> 2