Skip to content
Advertisement

How can I convert a string with dot and comma into a float in Python

How can I convert a string like 123,456.908 to float 123456.908 in Python?


For ints, see How to convert a string to a number if it has commas in it as thousands separators?, although the techniques are essentially the same.

Advertisement

Answer

Just remove the , with replace():

float("123,456.908".replace(',',''))
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement