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
.
I could replace the commas with empty strings before I try to convert it, but that feels wrong somehow. Is there a better way?
For float
values, see How can I convert a string with dot and comma into a float in Python, although the techniques are essentially the same.