0

I'm having a problem with my code. So I know I can't multiply what I have by the string, but I don't really know of any other way to do this. The length comes from an external file show below:

FH4536.266

Here is the part of my code with the issue:

String length = line.substring(4);
           String age = line.substring(2,4);
           double h = 0;
           String space = " ";

           if(gender == 'M')
           {
               switch(bone)
               {
                   case 'F':
                   h = 69.089 + (2.238 * length);
                   break;

I want to be able to multiply the length, but I don't know how I can do this. Could someone please explain on how I can do this? All the feedback/help is greatly appreciated.

user2989139
  • 71
  • 1
  • 6

2 Answers2

2

You have to parse string to double:

double length = Double.parseDouble(line.substring(4));
knagode
  • 5,816
  • 5
  • 49
  • 65
1

Convert the length to a numeric type (double) using double lenDbl = Double.parseDouble(length); (with appropriate exception handling)

Double.valueOf() should also work - valueof returns a Double class instance. parseDouble returns a double primitive type.

John3136
  • 28,809
  • 4
  • 51
  • 69