转换指数在python为十进制 [英] convert exponential to decimal in python

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

问题描述

我在蟒蛇的数组,其中包含一套价值,其中一些是

I have an array in python that contains a set of values, some of them are

2.32313e + 07

2.32313e+07

2.1155e + 07

2.1155e+07

1.923e + 07

1.923e+07

11856

112.32

如何转换的指数形式的十进制格式

How do I convert the exponential formats to the decimal format

其他:有没有一种方法,我可以在UNIX使用awk打印出来的时候,指数直接转换为十进制

Additional: Is there a way I can convert the exponent directly to decimal when printing out in UNIX with awk?

推荐答案

我想你有一个列表,而不是一个数组,但这里并没有太大的差别;在2.6和更早版本的Python,是这样的:

I imagine you have a list rather than an array, but here it doesn't make much of a difference; in 2.6 and earlier versions of Python, something like:

>>> L = [2.32313e+07, 2.1155e+07, 1.923e+07, 11856, 112.32]
>>> for x in L: print '%f' % x
... 
23231300.000000
21155000.000000
19230000.000000
11856.000000
112.320000

在2.6或更高版本中, .format 方法。我想大家都知道,这些数字本身,数字,都没有任何格式 - 这是的字符串的您格式化数字的获得,例如对于输出,即在一些格式。顺便说一句,在该%F 变种可以让你控制小数,宽度,对齐等数 - 很难准确地提示你可能想要的东西没有进一步的规范,从你

and in 2.6 or later, the .format method. I imagine you are aware that the numbers per se, as numbers, aren't in any "format" -- it's the strings you obtain by formatting the numbers, e.g. for output, that are in some format. BTW, variants on that %f can let you control number of decimals, width, alignment, etc -- hard to suggest exactly what you may want without further specs from you.

在awk中,你可以使用的printf

In awk, you can use printf.

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

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