Changing Text to Float

I am trying to turn a value that I assigned to a label into an int so I can store it as a number in the data table. I got it to assign correctly as a text, but when I want to place it into the Datatable, It said I cannot put text in number column. So, I tried to convert it into an int or float but got this error. Could use some help, please. See below

Why Is the below code not working? I keep getting an error that states:

ValueError: could not convert string to float: ‘’ at [Main, line 96]
(Line 96 is - HW1 = int(float(HW)) )

    HW = self.TH.text
    print(HW)
    HW1 = int(float(HW)) ```

What is the output of print(HW)?

This is the output when printed: 0:00:00

float() expects a string representing a floating number, the text you write is not a number.

So how do I take that and turn it into a number?

Some background about what I am trying to do:
I am adding clock in/out times and getting a total hours.

How do I make it into an int, or should I just change the data table value and make it a string instead of a number?

Just need some advice :grinning:

Well, you can’t make it an int because it is not an int.

What int would you expect to convert "1:23:45" into?

Perhaps you want to convert it into a time.
I’m on my cell now, and I may not remember correctly, but I think the datetime.strptime() is the function you are looking for.
You need to pass the string to convert and specify the expected format. You can Google it to find some examples.

Or you could split it into a list of strings with WH.split(":"), then convert each element of the list to int.

Our you could provide more details, and we could try to help a little more.

2 Likes

Thank you Stefano for guiding me out of my problem. I basically used time delta to get seconds and then divided by the 60 to get my minutes. Since minutes is an int/float, the data table accepted my input.

1 Like