I have a string that represents a number which uses commas to separate thousands. How can I convert this to a number in python?
>>> int("1,000,000")
Generates a ValueError.
ValueError
I could replace the commas with empty strings before I try to convert it, but that feels wrong somehow. Is there a better way?
import locale locale.setlocale( locale.LC_ALL, 'en_US.UTF-8' ) locale.atoi('1,000,000') # 1000000 locale.atof('1,000,000.53') # 1000000.53
1.4m articles
1.4m replys
5 comments
56.9k users