在python中将指数形式的数字转换为十进制形式 [英] Converting a number in exponential form to decimal form in python

查看:78
本文介绍了在python中将指数形式的数字转换为十进制形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常愚蠢的问题,假设我有一个数字 1.70000043572e-05 我应该如何将它转换为浮点数,即 0.0000170000043572.

I have a very silly question, suppose if i have a number 1.70000043572e-05 how should I convert it into float i.e. 0.0000170000043572.

推荐答案

您需要转换为浮点数并使用 str.format 指定精度:

You need to convert to a float and use str.format specifying the precision:

 In [41]: print "{:f}".format(float("1.70000043572e-05"))
 0.000017

# 16 digits 
In [38]: print "{:.16f}".format(float("1.70000043572e-05"))
0.0000170000043572

只要调用 float 就会得到 1.70000043572e-05.

Just calling float would give 1.70000043572e-05.

使用旧样式格式:

In [45]: print( "%.16f" % float("1.70000043572e-05"))
0.0000170000043572

这篇关于在python中将指数形式的数字转换为十进制形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆