PythonXYZ.com

Python 高级教程

    Python round() 函数

    Python 数字 Python 数字

    描述

    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 数字 Python 数字

    评论(0条)

    暂时还没有评论,第一个来评论吧!


    我要发表看法

    引用   粗体   链接   缩进  

    Copyright © 2017 pythonXYZ.com All Rights Reserved.
    反馈