P
Peter
Does anyone have an example of how to convert a String "26 1/2" to double 26.5 ?
Peter
Thank You
Peter
Thank You
26.5 ?Peter said:Does anyone have an example of how to convert a String "26 1/2" to double
Peter said:Does anyone have an example of how to convert a String "26 1/2" to double 26.5 ?
Peter
Thank You
public static double fracNumericStringToDouble(String str)
{
double mydouble;
int firstpartindex = str.indexOf(" ");
String wholepart = str.substring(0, firstpartindex);
System.out.println(wholepart);
int secondpartindex = str.indexOf("/");
denominator = str.substring(secondpartindex+1,secondpartindex);
System.out.println(numerator);
str.length());
System.out.println(denominator);
}
mydouble = (Double.parseDouble(numerator) /
Double.parseDouble(denominator));
mydouble += Double.parseDouble(wholepart);
return mydouble;
}
...
Please test
VisionSet said:26.5 ?
double myDouble;
if(myString.equals("26 1/2")) myDouble = 26.5;
Does anyone have an example of how to convert a String "26 1/2" to double 26.5 ?
VisionSet said:26.5 ?
double myDouble;
if(myString.equals("26 1/2")) myDouble = 26.5;
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.