+ 1
Java supports automatic type casting of integers to floating points
Can anyone give description with example of above line?
9 odpowiedzi
+ 1
Thanks Ondrej, Now I completely understand about automatic typecasting
int a=3;
float b=3.14f;
b=a; //This is automatic typecasting
System.out.println(b);
Output: 3.0
+ 1
Ondrej, Sorry I didn't understand completely cause I'm new to java.
double someDouble = Double.parseDouble("123");
above line means we are doing here type casting like converting string type to double but it is manual so where is automatic type casting??
+ 1
From string to double can not use casting. You can cast to double from these primitives types: byte, short, char, int, long, float.
That conversion from string to double I just added as an example because it is oftenly needed.
+ 1
Ok I got it Thanks for clarification, +1 Vote
+ 1
This page is not found http://docs.oracle.com/javase/jls/se8/html/jls-5.html
0
Just like this:
int someInt = 123;
double someDouble = (double) someInt;
From number string use this:
double someDouble = Double.parseDouble("123");
0
Your example is string conversion of float value.
0
Sorry for that link it should work now.