+ 1
In java how to change int var into float or double??
is it possible?
3 Respuestas
+ 12
Use type-casting:
int number = 5;
double d = (double) number;
+ 2
into double
public class IntToDouble{
public static void main(String args[]){
int i=200;
double d=i;
System.out.println(d);
}}
+ 2
into float
public class Conversions
{
public static void main(String args[])
{
int i1 = 10; // 4 bytes
float f1 = i1; // int is type converted to float
System.out.println("int value: " + i1); // prints 10
System.out.println("Converted float value: " + f1); // prints 10.0
}
}