分享

Python 之 向上取整、向下取整以及四舍五入函数

 daijingwen0 2017-01-18
  1. import math  
  2.   
  3. #向上取整  
  4. print "math.ceil---"  
  5. print "math.ceil(2.3) => ", math.ceil(2.3)  
  6. print "math.ceil(2.6) => ", math.ceil(2.6)  
  7.   
  8. #向下取整  
  9. print "\nmath.floor---"  
  10. print "math.floor(2.3) => ", math.floor(2.3)  
  11. print "math.floor(2.6) => ", math.floor(2.6)  
  12.   
  13. #四舍五入  
  14. print "\nround---"  
  15. print "round(2.3) => ", round(2.3)  
  16. print "round(2.6) => ", round(2.6)  
  17.   
  18. #这三个的返回结果都是浮点型  
  19. print "\n\nNOTE:every result is type of float"  
  20. print "math.ceil(2) => ", math.ceil(2)  
  21. print "math.floor(2) => ", math.floor(2)  
  22. print "round(2) => ", round(2)  


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多