gpt4 book ai didi

python - 在 python3 中获取输入时定义浮点精度

转载 作者:行者123 更新时间:2023-12-01 09:21:41 24 4
gpt4 key购买 nike

我想定义 float 作为输入的精度

NGAS=float(input("enter a number with 3 decimal places"))

我不想提及小数点后 3 位,而是想做相当于

print('%.3f%' % ESTART)

在接受输入时。因为,它影响了我的计算。

最佳答案

您可以对输入的数字进行四舍五入:

ngas = round(float(input("enter a number: ")), 3)

关于python - 在 python3 中获取输入时定义浮点精度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50759500/

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