gpt4 book ai didi

python - 将非常小的 python Decimal 转换为非科学记数法字符串

转载 作者:太空狗 更新时间:2023-10-29 20:56:17 26 4
gpt4 key购买 nike

我正在使用 Python Decimal 类进行精确的浮点运算。我需要将结果编号一致地转换为标准符号编号作为字符串。但是,默认情况下,非常小的十进制数以科学记数法呈现。

>>> from decimal import Decimal
>>>
>>> d = Decimal("0.000001")
>>> d
Decimal('0.000001')
>>> str(d)
'0.000001'
>>> d = Decimal("0.000000001")
>>> d
Decimal('1E-9')
>>> str(d)
'1E-9'

如何让 str(d) 返回 '0.000000001'

最佳答案

'{:f}'.format(d)
Out[12]: '0.000000001'

关于python - 将非常小的 python Decimal 转换为非科学记数法字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22490568/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com