Linux 拨号vps windows公众号手机端

python中使用round函数保留小数点任意位数

lewis 6年前 (2019-03-30) 阅读数 12 #程序编程
文章标签 pythonround函数

在python中使用round()函数保留小数点任意位数的方法

round:round()函数的作用是用于返回浮点数 x 的四舍五入值。

round()函数语法:

round( x [, n] )

参数:

x:数字表达式。

n:表示需保留的小数点位数,默认值为 0。

round()函数使用方法:

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))

输出结果为:

round(70.23456) : 70

round(56.659,1) : 56.7

round(80.264, 2) : 80.26

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门