Python学习教程(learning Python)--1.2.4 Python格式化输出科学计数

时间:2023-03-09 01:40:43
Python学习教程(learning Python)--1.2.4 Python格式化输出科学计数

Python在浮点数据输出时,可以采用科学计数法的方式输出。

现举两个例子说明一下如何使用。

eg1. 无精度要求的科学计数法浮点数据输出

>>> print(format(12345.6789, 'e'))

输出结果为:

1.234568e+04

  eg2 有精度要求的科学计数法浮点数据输出

>>>print(format(12345.6789, '.2e'))

输出结果为:

1.23e+04

对比以上两个小程序的结果,可以看出format格式控制字里的2的含义是保留2为小数点。 

智普教育Python www.jeapedu.com

———————————————————————————————————————————