TuffBee TuffBee - 1 year ago 88
SQL Question

Sum of multiple selected checkboxes in JAVA

If I use the "+ " sign it will just concatenate the values, but I need to find the mathematical values. I need to insert the quantity of a product. How to find the sum when multiple checkboxes are selected?
I have tried this which concatenates.. Also the values need to go into the database, it is working with the concatenated values..

qty= chckbx1.getText();

if(chckbx1.isSelected() && chckbx5.isSelected()){
qty= chckbx1.getText() + chckbx5.getText();

Answer Source

You need to parse it to Double using Double.parseDouble()

qty= (Double.parseDouble(chckbx1.getText()) + Double.parseDouble(chckbx5.getText())) + "";