取整的几种方法:
1、四舍五入 round(x)
pthon中取整的几个方法round、int、math

 

2、向下取整  int(x)

pthon中取整的几个方法round、int、math


3、取商和余

pthon中取整的几个方法round、int、math



4、向上取整,需要用到math.ceil(x)(可以理解成大于x且最接近x的整数)
import math
pthon中取整的几个方法round、int、math

5、向下取整,要用math.floor(x)(可以理解成小于x或这个表达式且最接近x的整数)

pthon中取整的几个方法round、int、math

 


6、分别取小数和整数部分,用math.modf(),返回一个含小数和整数部分的元祖

pthon中取整的几个方法round、int、math

 


 
                    
            
                

相关文章:

  • 2022-01-29
  • 2021-07-21
  • 2022-12-23
  • 2022-01-31
  • 2022-12-23
  • 2021-11-23
  • 2022-01-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2021-09-15
相关资源
相似解决方案