Python3基础 str format 四舍六入五凑偶 保留一位小数
- Python : 3.7.0
- OS : Ubuntu 18.04.1 LTS
- IDE : PyCharm 2018.2.4
- Conda : 4.5.11
- typesetting : Markdown
code
coder@Ubuntu:~$ source activate py37
(py37) coder@Ubuntu:~$ ipython
Python 3.7.0 (default, Jun 28 2018, 13:15:42)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: # 四舍
In [2]: "{0:.1f}".format(27.54)
Out[2]: '27.5'
In [3]: "{0:.1f}".format(27.64)
Out[3]: '27.6'
In [4]:
In [4]: # 六入
In [5]: "{0:.1f}".format(27.56)
Out[5]: '27.6'
In [6]: "{0:.1f}".format(27.66)
Out[6]: '27.7'
In [7]:
In [7]: # 五凑偶
In [8]: "{0:.1f}".format(27.55)
Out[8]: '27.6'
In [9]: "{0:.1f}".format(27.65)
Out[9]: '27.6'
In [10]: exit
(py37) coder@Ubuntu:~$ source deactivate
coder@Ubuntu:~$
resource
- [文档] docs.python.org/3
- [规范] www.python.org/dev/peps/pep-0008
- [规范] zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules
- [源码] www.python.org/downloads/source
- [ PEP ] www.python.org/dev/peps
- [平台] www.cnblogs.com
- [平台] gitee.com
Python具有开源、跨平台、解释型、交互式等特性,值得学习。
Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。
代码的书写要遵守规范,这样有助于沟通和理解。
每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。
Python3基础 str format 四舍六入五凑偶 保留一位小数的更多相关文章
- Python3基础 str format 位置参数与关键字参数
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 str format 输出花括号{}
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Math.Round四舍六入五取偶Math.Ceiling只要有小数都加1Math.Floor总是舍去小数
1.Math.Round:四舍六入五取偶 引用内容 Math.Round(0.0) //0Math.Round(0.1) //0Math.Round(0.2) //0Math.Round(0.3) / ...
- Double 数据保留两位小数一:五舍六入
package com; public class T2 { public static void main(String[] args) { System.out.println(calculate ...
- Python3基础 str translate 将指定字符转换成另一种特定字符
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 str 循环输出list中每个单词及其长度
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 str 通过拆分字符串与插入新的内容形成新的字符串
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 str while+iter+next 字符串的遍历
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 str split 用指定的字符将字符串分割
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
随机推荐
- Elasticsearch教程-从入门到精通(转)
原文:http://mageedu.blog.51cto.com/4265610/1714522?utm_source=tuicool&utm_medium=referral 各位运维同行朋友 ...
- IO流(10)复制多级文件夹
import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.File;import ja ...
- 怎么设置输入的EditText字母自己主动大写
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/t80t90s/article/details/25048917 复于: 2013-09-06 09: ...
- Unity 小知识
1.如何使物体颜色成2D效果 点开材质球的Shader属性,选择Unlit/Color 2.画布属性中的UI Scale Mode中可以设为 S W S S,这样屏幕大小缩放时,画布内的物体大小随之缩 ...
- [na]timewait优化
解决timewait 加入一条socket配置,重用ip和端口 phone=socket(AF_INET,SOCK_STREAM) phone.setsockopt(SOL_SOCKET,SO_REU ...
- 机器学习理论基础学习3.2--- Linear classification 线性分类之线性判别分析(LDA)
在学习LDA之前,有必要将其自然语言处理领域的LDA区别开来,在自然语言处理领域, LDA是隐含狄利克雷分布(Latent Dirichlet Allocation,简称LDA),是一种处理文档的主题 ...
- 机器学习理论基础学习13--- 隐马尔科夫模型 (HMM)
隐含马尔可夫模型并不是俄罗斯数学家马尔可夫发明的,而是美国数学家鲍姆提出的,隐含马尔可夫模型的训练方法(鲍姆-韦尔奇算法)也是以他名字命名的.隐含马尔可夫模型一直被认为是解决大多数自然语言处理问题最为 ...
- 接口测试xml格式转换成json
未经允许,禁止转载!!!! 接口测试一般返回的是xml和json,现在大多数时候是返回成json的格式,但是有时候也会出现xml格式, 由于xml格式的文件阅读起来不是很容易懂,所以尽量将xml转换成 ...
- react native 示例代码
https://react.rocks/tag/ReactNative?show=60 https://github.com/ReactNativeNews/React-Native-Apps
- 54. Spiral Matrix(剑指offer--19)
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...