Java String to double

Java converts string to double using Double.parseDouble(String)

package com.w3schools;

public class StringToDouble {
  public static void main(String args[]){
	String str="546.307";

	//convert String to double
	double var= Double.parseDouble(str);
	System.out.println(var);
  }
}

Output

546.307

 

Java converts string to double using Double.valueOf(String)

package com.w3schools;

public class StringToDouble {
  public static void main(String args[]){
	String str="546.307";

	//convert String to double
	double var= Double.valueOf(str);
	System.out.println(var);
  }
}

Output

546.307