convert int to double java code example

Example 1: string to double java

public class stringtodouble {
	public static void main(String args) {
    	String string = "1.23";
      	double decimal = Double.parseDouble(string);
    }
}

Example 2: java int to double

// Primitive type
int myInt = 5;
double myDouble = (double)myInt;		// explicit cast
myDouble = myInt;						// implicit cast
// Object type
Double myDouble = new Double(myInt)		// via constructor
myDouble = Double.valueOf(myInt)		// via valueOf

Example 3: int to double java

Double d= new Double(i);//first way  
Double d2=Double.valueOf(i);//second way

Example 4: int to double java

double d=i;

Tags:

Java Example