I'm studying java and doing some exercises. I am doing an exercise where I passed 2 values to be formatted, but when I run the program the following error, if I only pass 1 value it works but with 2 it gives the error.
Exception in thread "main" java.lang.NumberFormatException: multiple points at sun.misc.FloatingDecimal.readJavaFormatString (Unknown Source) at sun.misc.FloatingDecimal.parseDouble (Unknown Source) at java.lang.Double.parseDouble (Unknown Source) at TestMain.formataNumber (TestMain.java:37) at TestMain.main (TestMain.java:22)
Below is the code, if someone can give me a hint thanks
public static void main(String[] args) {
double salario = 4520;
double resto = 0;
double imposto1 = 0;
double imposto2 = 0;
double impostoAPagar = 0;
if(salario > 4500){
resto = formataNumero(salario % 4500); //guarda o resto da divisao de 4520 por 4500
salario = salario - resto;
imposto1 = (salario - 3000) * 0.18; //
imposto2 = salario - (salario - 3000) * 0.08;
impostoAPagar = imposto1 + imposto2;
impostoAPagar = formataNumero(impostoAPagar);
System.out.println("Numero formatado: "+resto);
System.out.println("Imposto a pagar: "+impostoAPagar);
}
} //Fim do main
public static double formataNumero(double valor){
double numeroFormatado = 0;
DecimalFormat formatador = new DecimalFormat();
formatador.applyPattern("###,###.00; (###,###.00)");
return Double.parseDouble(formatador.format(valor).replaceAll(",", "."));
}
}