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

作者:goldensun 时间:2023-05-01 11:57:10 

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

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


round( x [, n] )

参数

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

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


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

标签:Python
0
投稿

猜你喜欢

  • python/golang实现循环链表的示例代码

    2021-10-31 23:32:20
  • firefox通过XUL实现text-overflow:ellipsis的效果

    2008-07-08 19:12:00
  • Vue3中的setup语法糖、computed函数、watch函数详解

    2024-04-29 13:09:33
  • DataFrame 数据合并实现(merge,join,concat)

    2022-03-28 04:24:02
  • python爬虫爬取淘宝商品信息

    2023-07-04 10:33:24
  • python中ASCII码字符与int之间的转换方法

    2023-05-20 08:47:29
  • 简单的网站页面有什么好处

    2007-11-15 06:28:00
  • Anaconda配置pytorch-gpu虚拟环境的图文教程

    2022-06-15 14:42:20
  • python通过nmap扫描在线设备并尝试AAA登录(实例代码)

    2021-08-06 23:23:42
  • eWebEditor不支持IE8/IE7的解决方法

    2010-02-28 10:27:00
  • Django之PopUp的具体实现方法

    2023-03-26 13:04:54
  • Python实现的KMeans聚类算法实例分析

    2021-06-28 04:44:49
  • Python图像处理之直线和曲线的拟合与绘制【curve_fit()应用】

    2021-01-28 10:30:49
  • Python爬虫分析微博热搜关键词的实现代码

    2022-11-29 16:13:44
  • Flask中jinja2的继承实现方法及实例

    2022-09-24 12:31:09
  • TensorFlow入门使用 tf.train.Saver()保存模型

    2023-06-07 15:29:45
  • python得到单词模式的示例

    2021-04-22 08:25:48
  • JS循环中正确使用async、await的姿势分享

    2024-05-25 15:18:56
  • Python实现屏幕代码雨效果的示例代码

    2021-08-29 12:48:09
  • Python通过队列实现进程间通信详情

    2023-07-24 17:49:44
  • asp之家 网络编程 m.aspxhome.com