I have arbitrary String with currencies like 100,00€ or $100.00 or 100.00USD (arbitrary lenght, any valid Currency on earth both Symbol and ISO-Code )…(=like 100.000.000,00 EUR). There is no guarantee that the currencies are correct, it might be an invalid Symbol or Character or at the wrong position (after or before the number)…
What is the easiest way to get:
- The integer part
- The decimal part
- The Currency (if valid)
I know of NumberFormat/CurrencyFormat but this class is only usefull if you know the exact locale in advance and seems to be working only to correctly formatted string… asw well only returns the number, not the currency…
Thank you very much!
Markus
To help answer this question we should first ask, what does a currency string consist of?
Well it consists of:
Character.isSpaceCharorCharacter.isWhitespace)I will soon create a concrete class for this question, but for now I hope this provides a starting
point for you. Note, however, that some currency symbols such as
$cannot uniquely identify a particular currency without more, as I explained in my comment.Edit:
Just in case someone else visits this page and encounters the same problem, I’ve written the code below that answers the question more concretely. The code below is in the public domain.
It returns a CurrencyValue object defined below.