Use the parseDouble()
method to convert a string value to a double value
In this step, we will convert a string value to its equivalent double value using the parseDouble()
method.
Code block:
String str = "8.97";
double num = Double.parseDouble(str);
System.out.println("Double value of "+str+" is "+num);
This will output:
Double value of 8.97 is 8.97
In the code block above, we created a string variable str and initialized it with the value "8.97". Then, we called the parseDouble()
method, passing the string variable as an argument, and assigned the returned double value to the double variable num. Finally, we printed the double variable.