首页 > 编程语言 > 详细

Python3 round() 函数

时间:2019-03-05 15:44:05      阅读:156      评论:0      收藏:0      [点我收藏+]

Python3 round() 函数

技术分享图片 Python3 数字


描述

round() 方法返回浮点数x的四舍五入值。


语法

以下是 round() 方法的语法:

round( x [, n]  )

参数

  • x -- 数字表达式。
  • n -- 表示从小数点位数,其中 x 需要四舍五入,默认值为 0。

返回值

返回浮点数x的四舍五入值。


实例

以下展示了使用 round() 方法的实例:

#!/usr/bin/python3

print ("round(70.23456) : ", round(70.23456))
print ("round(56.659,1) : ", round(56.659,1))
print ("round(80.264, 2) : ", round(80.264, 2))
print ("round(100.000056, 3) : ", round(100.000056, 3))
print ("round(-100.000056, 3) : ", round(-100.000056, 3))

以上实例运行后输出结果为:

round(70.23456) :  70
round(56.659,1) :  56.7
round(80.264, 2) :  80.26
round(100.000056, 3) :  100.0
round(-100.000056, 3) :  -100.0

Python3 round() 函数

原文:https://www.cnblogs.com/fpzs/p/10477160.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!