python3 的 round 函数感觉很别扭,其运算结果与习惯不相符。特记录下来:

代码


'''
python 3的 round 函数 是“四舍六入五成双”的 https://www.zhihu.com/question/20128906
'''
print('python 3的 round 函数:四舍六入五成双') print('\nround(-3.5) = ', round(-3.5)) print('\nround(-2.5) = ', round(-2.5))
print('round(-1.5) = ', round(-1.5)) print('\nround(-0.5) = ', round(-0.5))
print('round(0.5) = ', round(0.5)) print('\nround(1.5) = ', round(1.5))
print('round(2.5) = ', round(2.5)) print('\nround(3.5) = ', round(3.5))
print('round(4.5) = ', round(4.5)) print('\nround(5.5) = ', round(5.5))
print('round(6.5) = ', round(6.5)) print('\nround(6.5000000000000001) = ', round(6.5000000000000001)) # 小数点后16位
print('round(6.500000000000001) = ', round(6.500000000000001)) # 小数点后15位

效果图

python3 的 round 函数的 练习的更多相关文章

  1. Python3 round() 函数

    Python3 round() 函数  Python3 数字 描述 round() 方法返回浮点数x的四舍五入值. 语法 以下是 round() 方法的语法: round( x [, n] ) 参数 ...

  2. (转)Python3的四舍五入round()函数坑爹?不,更科学!

    原文:https://blog.csdn.net/lly1122334/article/details/80596026 Python3的四舍五入round()函数坑爹?不,更科学!Python2中, ...

  3. 【Python3之内置函数】

    内置函数 简单来说就是python3本身就自带的函数. abs(x) abs()返回一个数字的绝对值.如果给出复数,返回值就是该复数的模 print(abs(-1100)) 输出:1100 all() ...

  4. Python 中关于 round 函数的坑

    round函数很简单(而且不需要引入math模块),对浮点数进行近似取值,保留几位小数. 比如 # -*- coding: UTF-8 -*- r1=round(12.12345,3) r2=roun ...

  5. python中关于round函数的小坑

    这个一直都想写,但是因为这个点比较小,所以一直懒得动手.不过还是补上吧,留着早晚是个祸害. round函数很简单,对浮点数进行近似取值,保留几位小数.比如 >>> round(10. ...

  6. python3内置函数大全(顺序排列)

    python3内置函数大全 内置函数 (1)abs(),   绝对值或复数的模 1 print(abs(-6))#>>>>6 (2)all() 接受一个迭代器,如果迭代器的所有 ...

  7. python3内置函数大全

    由于面试的时候有时候会问到python的几个基本内置函数,由于记不太清,就比较难受,于是呕心沥血总结了一下python3的基本内置函数 Github源码:        https://github. ...

  8. 08 . Python3高阶函数之迭代器、装饰器

    Python3高阶函数之迭代器.装饰器 列表生成式 推导式就是构建比较有规律的列表,生成器. 孩子,我现在有个需求,看列表[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],我要求你把列表里 ...

  9. oracle的round函数和trunc函数

    --Oracle trunc()函数的用法/**************日期********************/1.select trunc(sysdate) from dual --2013- ...

随机推荐

  1. 【three.js练习程序】动画效果,100个方块随机运动

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. c#中Indexof()和Split()的用法

    C#中IndexOf的使用 indexOf() 查找字串中指定字符或字串首次出现的位置,返首索引值,如: str1.IndexOf("字"): //查找“字”在str1中的索引值( ...

  3. 03-01_WebLogic一些概念名词

    WebLogic一些概念名词 域(Domain) 管理服务器(Administrative Server) 被管服务器(Managed Server,受管服务器) 集群(Cluster) 机器(Mac ...

  4. python自学——文件修改

    #如何修改文件,我们知道文件因为在磁盘上已经有储存了,后面要更新或修改,只能在在原来文件后面追加使用f=open("wenjian_name","r+",enc ...

  5. ejb-jar.xml

    所有bean类(无论是会话bean还是实体bean)必须实现的最基本的接口是javax.ejb.EnterpriseBean接口. 所有的会话bean必须实现javax.ejb.SessionBean ...

  6. MySQL出现Waiting for table metadata lock的场景浅析

    MySQL版本为5.6.12. 在进行alter table操作时,有时会出现Waiting for table metadata lock的等待场景.而且,一旦alter table TableA的 ...

  7. You are not late! You are not early!

    Do you think you are going No Where in Life? STOP! Take a deep breathe THINK! New York is three hour ...

  8. 安装和配置Apache服务器(下)

    Apache的配置文档:http://httpd.apache.org/docs/current/. 1.监听端口: 默认的端口号为80端口,如果端口号冲突改为8080端口. 注:每改一次httpd. ...

  9. 【Alpha Go】Day 1 !

    [Alpha Go]Day 1 ! Part 0 · 简要目录 Part 1 · 任务分配 Part 2 · 他日安排 Part 3 · 预期任务量 Part 4 · 团队贡献值计算原则 Part 1 ...

  10. Alpha事后诸葛亮(阳光普照队)

    Alpha事后诸葛亮 设想和目标 1.实现文字识别,以用户喜欢的图片做背景将其保存,生成新的图片. 2.时间比较赶,主要是因为队员对于Android开发方面的了解不多,可以说是几乎没有,需要一步一步的 ...