gpt4 book ai didi

python - 在 Python 中将 float 打印为整数

转载 作者:行者123 更新时间:2023-11-28 19:38:52 25 4
gpt4 key购买 nike

所以我想将 float 打印为整数。我有一个名为“percentage”的 float ,它应该类似于 percentage=36.1,我想将它打印为一个 int 数字,逗号后面缺少数字。

我使用下面的代码,这更像是使用 C 逻辑:

percentage=36.1
print "The moisture percentage is at %d %.", percentage

但这会产生错误。我将如何对其进行改革以使其在 Python 中运行?我要打印的是:“含水率是36%。”

最佳答案

percentage=36.1
print "The moisture percentage is at %i%% " %percentage

关于python - 在 Python 中将 float 打印为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44176475/

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