源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2021-02-12 06:09 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:简单介绍Python中的round()方法
 round()方法返回 x 的小数点四舍五入到n个数字。 [b]语法[/b] 以下是round()方法的语法:
round( x [, n] )

[b]参数[/b] [list] [*]    x --这是一个数值表达式[/*] [*]    n --这也是一个数值表达式[/*] [/list] [b]返回值[/b] 该方法返回 x 的小数点四舍五入到n个数字 [b]例子[/b] 下面的例子显示了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

  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部