gpt4 book ai didi

python - PyQt - 如何在 QLabel 中禁用科学记数法

转载 作者:行者123 更新时间:2023-11-28 18:53:01 25 4
gpt4 key购买 nike

我对大数使用 Decimal 模块,但对于小于 0.00001 的值,它会变成科学记数法。有什么方法可以禁用它以便显示所有小数位:

round(Decimal(str(value)), 9)

'{0:f}'.format(value) 不起作用,因为它显示所有数字,例如0.0000100000 而不是 0.00001

我只想在舍入 0.0000000015 后显示 0.000000002。

我试过了

def set_decimals(self, value, decimals):
val = '{0:f}'.format(Decimal(str(value)))
rnd_value = round(Decimal(val), decimals)
return str(rnd_value)

但它仍然将其转换为科学计数法

谢谢。

最佳答案

我找不到比这个更好的解决方案了:

def regularNotation(value):
"""Sometimes str(decimal) makes scientific notation. This function makes the regular notation."""
v = '{:.14f}'.format(value).rpartition('.') # 14 digits in fractional part
return v[0] + (v[1] + v[2]).rstrip('.0') # strip trailing 0s after decimal point

关于python - PyQt - 如何在 QLabel 中禁用科学记数法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9260469/

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