gpt4 book ai didi

python - 在 Python 中截断为小数点后三位

转载 作者:IT老高 更新时间:2023-10-28 21:46:05 34 4
gpt4 key购买 nike

我如何获得 1324343032.324?

如下所示,以下方法不起作用:

>>1324343032.324325235 * 1000 / 1000
1324343032.3243253
>>int(1324343032.324325235 * 1000) / 1000.0
1324343032.3239999
>>round(int(1324343032.324325235 * 1000) / 1000.0,3)
1324343032.3239999
>>str(1324343032.3239999)
'1324343032.32'

最佳答案

如果您想将其保留为 float,您可以在其周围使用额外的 float()

%.3f'%(1324343032.324325235)

关于python - 在 Python 中截断为小数点后三位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8595973/

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