在 Python 中截断为三位小数 [英] Truncate to three decimals in Python

查看:55
本文介绍了在 Python 中截断为三位小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得 1324343032.324?

How do I get 1324343032.324?

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

As you can see below, the following do not work:

>>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().

You can use an additional float() around it if you want to preserve it as a float.

%.3f'%(1324343032.324325235)

这篇关于在 Python 中截断为三位小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆