描述

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


语法

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

round( x [, n]  )

参数

  • x -- 数值表达式。
  • n -- 数值表达式,保留几位小数

返回值

返回浮点数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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2021-12-28
  • 2021-12-16
  • 2021-12-13
  • 2022-03-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
  • 2021-09-24
  • 2021-05-24
  • 2021-10-07
  • 2022-12-23
相关资源
相似解决方案