How to get the sum of Doubles
that where parsed from a JTable
?
I'm Building a Client/Server Application, and I'm Stuck on a Little issue.
I want get the sum of values of a column in a JTable
, this column contains String
objects with #,##
format, so when I try to parse them into doubles with a loop I get this error:
java.lang.NumberFormatException: For input string: "0,55"
Here is the JTable
image:
And here is the code that I tried so far:
private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {
Double summl = 0.0;
for(int i = 0; i < jTable1.getRowCount(); i++){
summl=summl+Double.parseDouble(jTable1.getValueAt(i,5).toString());
}
System.out.println("summl = "+summl);
}
I think the problem is with the comma in the number. You should try to parse the numbers using NumberFormat class.
E.G.: