Search code examples
javaregexcurrency

Number/Currency Formatting


I do have Bulgarian currency in a format like +000000027511,00.I want to convert this format to 27511.00,I have tried it and got using substring combinations and regex,Is there any patterns or regex to do it in more simplified way?

Implementation I tried,

String currency= "+000000027511"; // "[1234]" String
String currencyFormatted=currency.substring(1);
System.out.println(currencyFormatted.replaceFirst("^0+(?!$)", ""));

Solution

  • Something like this:

    String s = "+000000027511,00";
    String r = s.replaceFirst("^\\+?0*", "");
    r = r.replace(',', '.');