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!
            Asked
            
        
        
            Active
            
        
            Viewed 318 times
        
    1
            
            
        
        Python 123
        
- 59
 - 1
 - 13
 
3 Answers
3
            Get rid of any comma as it has no meaning for the number itself.
float("2,900.99".replace(",", ""))
Results in 2900.99
        Jonathan1609
        
- 1,809
 - 1
 - 5
 - 22
 
1
            
            
        You need to remove the commas first, like this:
float("2,900.99".replace(",",""))
returns 2900.99
        sj95126
        
- 6,520
 - 2
 - 15
 - 34
 
1
            
            
        You need to remove the , by replacing it with nothing and then to convert the string to float.
float("2,900.99".replace(',',''))
        Prophet
        
- 32,350
 - 22
 - 54
 - 79