ControlC ControlC.com

java-tut-typecasting-primitives-casting-floating-point-to-floating-point-1

Views: 94Total Chars: 538
Created: 11/28/24 3:43:01AM ET
Self Destructs: Never
public class SampleConversion{

public static void main(String[]args){
//upcasting float literal to double
double doubleVar = 5.55f;
System.out.println(doubleVar);

//converting double literal to float
//Just like other primitive types,
//downcasting double to float can
//cause data loss if the double
//value that is gonna be casted exceeds
//the bit range of float. Double is
//64bits whereas float is 32bits
float floatVar = (float)200.598333d;
System.out.println(floatVar);
}
}
538 chars, 64 words, 18 lines·Create new version