Convert double to float in Java

Just cast your double to a float.

[java]double d = getInfoValueNumeric();
float f = (float)d;

[/java]

Also notice that the primitive types can NOT store an infinite set of numbers:

[java]float range: from 1.40129846432481707e-45 to 3.40282346638528860e+38
double range: from 1.7e–308 to 1.7e+308
[/java]

Leave a Comment