Friday, August 24, 2018

python - How do I parse a string to a float or int?




In Python, how can I parse a numeric string like "545.2222" to its corresponding float value, 545.2222? Or parse the string "31" to an integer, 31?



I just want to know how to parse a float str to a float, and (separately) an int str to an int.


Answer



>>> a = "545.2222"
>>> float(a)
545.22220000000004
>>> int(float(a))
545


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...