0

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

2
  • 3
    What int do you expect to get back? Commented Oct 16, 2022 at 15:18
  • my bad, i want to use this number as a time.sleep i found out now that i have to convert it to float to use it in time.sleep Commented Oct 16, 2022 at 15:22

2 Answers 2

1

convert it to float first and then to int

x = "0.5"
print(int(float(x)))
Sign up to request clarification or add additional context in comments.

Comments

0

you can convert this string to float and than use floor or ceil funtions for valid int

x = float(x)
x = math.floor(x) # or math.ceil() by your choice
x = int(x)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.