'Can you cast a string of a float number into an integer in python? (in 1 step) [duplicate]
Example:
string = "12.4"
x = int(string)
Just curious if there's a way to do this directly, or if you just have to convert to float then to int as 2 steps.
Solution 1:[1]
x="12.4"
x=int(float(x))# this float(x) first converts the string x into float and
#then int() function converts now newly float x int int x
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Beginner |
