Java examples for Language Basics:double
Convert String to Double example
public class Main { public static void main(String[] args) { //1. Construct Double using constructor. Double dObj1 = new Double("100.564"); System.out.println(dObj1);/*from w ww.ja va2 s. co m*/ //2. Use valueOf method of Double class. This method is static. String str1 = "100.476"; Double dObj2 = Double.valueOf(str1); System.out.println(dObj2); /* To convert a String object to a double primitive value parseDouble method of Double class. */ String str2 = "7.39"; double d = Double.parseDouble(str2); System.out.println(d); } }