How to convert a string with dot and comma into a float in Python?

Sometimes, we want to convert a string with dot and comma into a float in Python.

In this article, we’ll look at how to convert a string with dot and comma into a float in Python.

How to convert a string with dot and comma into a float in Python?

To convert a string with dot and comma into a float in Python, we can remove the commas from the string before we call float.

For instance, we write

n = float("123,456.908".replace(',',''))

to call float with a string that has the commas removed from the "123,456.908" string with

"123,456.908".replace(',','')

Then we can convert the string to a float.

Conclusion

To convert a string with dot and comma into a float in Python, we can remove the commas from the string before we call float.