Wednesday 11 January 2017

Convert double to float in java.

There are no on the way to convert the Double to Float.

Just cast your double to a float.
double d = getInfoValueNumeric();
float f = (float)d;
Also, notice that the primitive types can NOT store an infinite set of numbers:
float range: from 1.40129846432481707e-45 to 3.40282346638528860e+38
double range: from 1.7e308 to 1.7e+308

1) You can achieve it by using decimal formatter .

 double d = 2.342565656767E13;
     DecimalFormat decimalFormat = new DecimalFormat("#");
     System.out.println(decimalFormat.format(d));

2)You can also achieve it by Cast it .
double d = 2.342565656767E13;
float f = (float)d;

No comments:

Post a Comment