简单介绍Python中的round()方法

WBOY
Release: 2016-06-10 15:12:33
Original
1795 people have browsed it

 round()方法返回 x 的小数点四舍五入到n个数字。
语法

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

round( x [, n] )

Copy after login

参数

  • x --这是一个数值表达式
  • n --这也是一个数值表达式

返回值

该方法返回 x 的小数点四舍五入到n个数字
例子

下面的例子显示了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)

Copy after login

当我们运行上面的程序,它会产生以下结果:

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

Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!