I am trying to format double values to currency and then remove the euro sign but my application crashed. can someone tell me where am wrong please?
public class Formatting {
public static String replaceString(String text){
NumberFormat formatter = NumberFormat.getCurrencyInstance();
String moneyString = formatter.format(text);
System.out.println("epargne: "+moneyString);
return text.replaceAll("£", "");
}
public static String convert(double x){
return replaceString(Double.toString(x));
}
}
i called it as follows in class y
double x = a + b + c;
System.out.println(Formatting.convert(x));
formataccepts a double, no need to convert that value to a String.replaceAllrequires a regexp, you can just simply usereplacewhich requires a single char.