Python3 round() 函数

Python 3 教程 · 2019-02-05 14:44:20

描述

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

点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html

查看所有标签

Practical Django Projects, Second Edition

Practical Django Projects, Second Edition

James Bennett / Apress / 2009 / 44.99

Build a django content management system, blog, and social networking site with James Bennett as he introduces version 1.1 of the popular Django framework. You’ll work through the development of ea......一起来看看 《Practical Django Projects, Second Edition》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具