-2
Since I could not convert a String to Double, because it is decimal, I used Double.valueOf(String). doubleValue(). But when converting a String to Double with "." the numbers above 3 houses (1,000) are not stored in Double variable even with the above code, only numbers smaller than (1,000) are stored. How do I convert a String to decimal for calculations? ->Formatted field for monetary values.
Double vlprod=0.0;
ArrayList<String> valorUnitario = new ArrayList();
ArrayList<String> quantidade = new ArrayList();
if (lstProduto.isSelectionEmpty()) /*Verifica se foi selecionado um item na JList*/
{
JOptionPane.showMessageDialog(null, "Selecione um item na lista de produtos !");
}
else /*Se foi selecionado, pega o valor na posição do ArrayList referente ao índice da JList*/
{
int i= lstProduto.getSelectedIndex();
Double vl=Double.valueOf(valorUnitario.get(i)).doubleValue();
int qt=Integer.parseInt(quantidade.get(i));
vlprod=Double.valueOf(vlprod+(vl*qt)).doubleValue();
System.out.println(vlprod.toString());
}
Erro no Console: Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: multiple points
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1914)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)
Double.valueOf or Double.parseDouble already do that, did not understand your doubt. Present a [mcve] to demonstrate your problem.
– user28595