本文介绍了在编写python漂浮文件时压缩科学记数法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
写一个浮动到一个CSV写一些这样的:2.0628800997782577e-05$ b $ pre code c = csv.writer(open (file,wb))
c.writerow([var1,var2])
我试过了:
- 我已经在
StackOverflow上的其他答案中尝试了var1 ** 8,将它们提升到8的幂。
- 我也尝试了Decimal(var1),但是这并不能抑制科学的
表示法。
由于它被识别为文本而不是数字,这使得在Excel中处理输出变得困难。如何以非科学的十进制格式打印它?
解决方案
'%f '%your_var
或者控制精度:
'%0.10f'%your_var
Writing floats to a CSV writes some of them like this: 2.0628800997782577e-05
c = csv.writer(open(file, "wb")) c.writerow([var1, var2])
What I've tried:
- I have already tried var1**8 following other answers onStackOverflow, but this simply raises them to the power of 8.
- I have also tried Decimal(var1), but this does not suppress the scientificnotation.
This makes it difficult to process the output in excel afterwards as it's recognized as text and not a number. How can I print it in non-scientific, decimal notation?
解决方案
'%f' % your_var
Or to control the precision:
'%0.10f' % your_var
这篇关于在编写python漂浮文件时压缩科学记数法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
08-06 23:21