Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert String with "." to int in python

I want to convert a string with a point to a int
to us it in time

import time

x = "0.5"
time.sleep(int(x))

i tried it with this simple code but i get this error

ValueError: invalid literal for int() with base 10: '0.5'

is there an solutuion to convert the string to int

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

convert it to float first and then to int

x = "0.5"
print(int(float(x)))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading