1

I am trying to convert a string, "2,900.99", to a float. Trying float(int("2,900.99")) has not worked and float("2,900.99") is not working. The value is pulled from selenium and beautiful soup and the type of data is a string so I don't know how I can change the type of data. Thanks in advance for any answers!

0

3 Answers 3

3

Get rid of any comma as it has no meaning for the number itself.

float("2,900.99".replace(",", ""))

Results in 2900.99

Sign up to request clarification or add additional context in comments.

Comments

1

You need to remove the commas first, like this:

float("2,900.99".replace(",",""))

returns 2900.99

Comments

1

You need to remove the , by replacing it with nothing and then to convert the string to float.

float("2,900.99".replace(',',''))

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.