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

Bill Hileman
  • 2,798
  • 2
  • 17
  • 24
freezy361
  • 47
  • 7

2 Answers2

1

convert it to float first and then to int

x = "0.5"
print(int(float(x)))
YUVI_1303
  • 112
  • 8
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)