Skip to content
Advertisement

Parsing prices with Currency Symbol in Java

I want to parse a String that i have into a Number. This is the Code that i’m using but not working:

JavaScript

This results in a java.text.ParseException

So i want to match the String into a number, i don’t really care about the currency, but it would be nice to have.

I want the following kind of Strings matched:

JavaScript

Sure, there are ways with RegEx, but i think it would be kind of overkill.

Advertisement

Answer

Locale.GERMAN does not seem to have a currency symbol. Locale.GERMANY has the euro symbol as its currency (not the string “EUR”). Notice that blam1 and blam3 below cause parsing exceptions, the CurrencyFormat object only likes blam2.

JavaScript

I suspect that you will need to either find an open source currency parser that fits your need or write one yourself.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement