How can I convert currency strings to numerical values?

Question:

Is there a way to convert currency strings to floating values, for example:

Should be converted to:

Some currency strings have space between the dollar sign and the dollar value.

I am doing this because I am extracting the cost values from PDFs (which are converted to txt files) and do arithmetic on them. For example, a portion of text file looks like this:

And my code looks like this:

But those only extract the costs into string values.

Answer:


If you want the trailing 0 you’ll have to leave it as [string] until you do whaterver calculations you want with it.

Source:

How can I convert currency strings to numerical values? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply