String to double in java

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

package com.w3spoint;
 
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

Download this example.

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

package com.w3spoint;
 
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

Download this example.

Content Protection by DMCA.com
Please Share