Skip to main content
5 of 5
Removed improved code (should not be appended)
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Optimize parsing of number for currency conversion

I have written this working block, but is it optimized? I am getting currency in this format: 1.234,25.

public static String convertCurrency(String value, String exchangeCurrencyId)
{
    java.text.NumberFormat format = null;
    value = value.replaceAll("\\.", ",");
    char[] chars = value.toCharArray();
    chars[value.lastIndexOf(',')] = '.';
    value = new String(chars);
    value = value.replaceAll(",", "");
    Double price = Double.valueOf(value);
    price = price * (50); //exchange rate

    return price.toString();
}
eatSleepCode
  • 327
  • 1
  • 2
  • 9