Per the docs
Return an integer object constructed from a number or string x, or
return 0 if no arguments are given. If x is a number, return
x.int(). For floating point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string,
bytes, or bytearray instance representing an integer literal in radix
base.
Pay particular attention to "representing an integer literal". So your str
that you are attempting to convert cannot be a float, because that's a float literal, not an int literal.
So, as others have noted, you cannot go directly from a float literal to an int
, you need to convert the float
first:
x = '123.45'
int(float(x))
int
won't try to go from string to float to int implicitly. If you want to do this, be explicit:int(float('99.99'))
.round(float('99.99))
. Maybe look atMath.floor/ceil
depending on how you want it to round your number.