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 extract the integer from the string '$61.52' to use in the arithmetic oprations in python?

I am using Python.
How to do the addition of the strings $61.52 and $57.74 get the value as 119.26?

I tried using isdigit() but it is extracting numbers as 6152 and not as 61.52. I want to extract 61.52 from string $61.52.

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

>Solution :

What I would do:

amount1 = float('$61.52'.replace('$', ''))
amount2 = float('$57.74'.replace('$', ''))

result = amount1 + amount2

print(f'The sum is: ${result:.2f}')
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