[英]How can I convert a floating point number to an integer in python?
I have given an input of 3 arguments to a script from powershell and I want one of these to be the floating point number 0.0. 我从powershell给脚本输入了3个参数,我希望其中之一是0.0的浮点数。 I then try to convert this value from a string to an integer using time = int(time) but I get an error.
然后,我尝试使用time = int(time)将此值从字符串转换为整数,但出现错误。 Anyone know how I can get my variable inside the program to hold my float point number?
有人知道如何在程序中获取变量以保存浮点数吗? Thank you.
谢谢。
time = int(float(time))
Are you sure you want an integer here? 您确定要在这里整数吗? It doesn't make sense to pass in
"0.0"
if you want integer 0
. 如果要整数
0
则传递"0.0"
没有意义。 It sounds like either you should be passing in "0"
, or you should be storing it as a float. 听起来您应该传递
"0"
或将其存储为浮点数。
To store it as a float, just use 要将其存储为浮点数,只需使用
time = float(time)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.