【问题标题】:Python format Decimal near zero [duplicate]Python格式接近零的十进制[重复]
【发布时间】:2014-09-10 21:23:36
【问题描述】:

我正在尝试使用 decimal.Decimal python 模块解析接近 0 的数字:

>>> import decimal
>>> from decimal import Decimal
>>> Decimal("0.00000161")
Decimal('0.00000161')
>>> Decimal("0.00000061")
Decimal('6.1E-7')
>>> 

打印“0.00000061”而不是“6.1E-7”的最佳方法是什么?

【问题讨论】:

  • 科学记数法有什么问题?

标签: python numbers decimal


【解决方案1】:
In [157]: from decimal import Decimal

In [158]: x = Decimal("0.00000061")

In [159]: format(x, 'f')
Out[159]: '0.00000061'

【讨论】:

    【解决方案2】:
    from decimal import Decimal
    x = Decimal('0.00000061')
    print '{0:f}'.format(x)
    

    【讨论】:

      猜你喜欢
      • 2017-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-01
      • 2021-11-20
      • 2012-08-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多