Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to replace a commas with periods in text for decimal numbers in python

Python logo Python logo
Python logo

To replace commas with periods in text for decimal numbers in Python, you can use the `replace()` method of the `string` class.

Here is an example of how you could do this:

text = "The total cost is $1,234.56"

# Replace commas with periods
text = text.replace(',', '.')

print(text)

This will print the following output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The total cost is $1.234.56

Keep in mind that this will only work if the commas are used as decimal separators. If the commas are used as thousands separators, you will need to use a different approach to correctly convert the numbers to decimal format.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading