问题
I am trying to add row values of datatype(money) in which zeros after decimal are automatically formed in Jtable like these 55.0000 28.0000 60.0000 20.0000 50.0000
on runtime log showing this error
java.math.BigDecimal cannot be cast to java.lang.String
Here is the code for rows addition from Jtable
        double total = 0;
        for(int i = 0; i<table.getRowCount(); i++){
            double amount = Double.parseDouble((String) table.getValueAt(1, 6) );
            total+=amount;
        }
        totalSum.setText(String.valueOf(total));
*
Is there any way to add float type values??
- 
* 
回答1:
Try something like this:
BigDecimal total = BigDecimal.ZERO;
for (int i = 0; i < table.getRowCount(); ++i) {
    final BigDecimal amount = (BigDecimal)table.getValueAt(i, 6);
    total = total.add(amount);
}
totalSum.setText(total.toString());
回答2:
Change
double amount = Double.parseDouble((String) table.getValueAt(1, 6) );
to
double amount = table.getValueAt(1, 6).doubleValue();
There's no need to convert a BigDecimal to String just to make a double.
来源:https://stackoverflow.com/questions/45686654/java-math-bigdecimal-cannot-be-cast-to-java-lang-string