Python round() 函数

Python 教程 · 2019-02-01 22:58:21

描述

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

语法

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

round( x [, n]  )

参数

  • x -- 数值表达式。
  • n -- 数值表达式。

返回值

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

实例

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

#!/usr/bin/python

print "round(80.23456, 2) : ", round(80.23456, 2)
print "round(100.000056, 3) : ", round(100.000056, 3)
print "round(-100.000056, 3) : ", round(-100.000056, 3)

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

round(80.23456, 2) :  80.23
round(100.000056, 3) :  100.0
round(-100.000056, 3) :  -100.0

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

查看所有标签

The Definitive Guide to Django

The Definitive Guide to Django

Adrian Holovaty、Jacob Kaplan-Moss / Apress / 2007-12-06 / CAD 45.14

Django, the Python-based equivalent to the Ruby on Rails web development framework, is presently one of the hottest topics in web development today. In The Definitive Guide to Django: Web Development ......一起来看看 《The Definitive Guide to Django》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具