0

I need to make an if loop that if the column in excel says ''cov'' it should take the values in the 14th column and calculate them together. The thing is, I know when I take the values they will come as a string and I need to parse them in to a double, how can I do that?

if(workbook.getSheet(0).getCell(0, rowno+1).getContents().equals("cov")){
    for(int i=1; i<=8; i++){
        String excel = workbook.getSheet(0).getCell(13, rowno+1).getContents();
        System.out.println(excel);
        rowno++;
    }
}

It will print out the right values, but I cannot convert them nor calculate them together.

almightyGOSU
  • 3,731
  • 6
  • 31
  • 41

2 Answers2

0

Answer is here:

Convert String to double in Java

String excel = "99.99"; // example String
double value = Double.parseDouble(excel);
Community
  • 1
  • 1
Springfield762
  • 221
  • 1
  • 11
0

To parse string as double use below line:-

Double.parseDouble(excel)

And to sum up all in your loop instantiate one double variable "Double sum=0.0" outside the loop and initialize it with 0.0 and in your loop you can do sum+= Double.parseDouble(excel);

Kulbhushan Singh
  • 627
  • 4
  • 20