I want to print a double value in Java without exponential form.
double dexp = 12345678;
System.out.println(\"dexp: \"+dexp);
It shows this
I needed to convert some double to currency values and found that most of the solutions were OK, but not for me.
The DecimalFormat
was eventually the way for me, so here is what I've done:
public String foo(double value) //Got here 6.743240136E7 or something..
{
DecimalFormat formatter;
if(value - (int)value > 0.0)
formatter = new DecimalFormat("0.00"); // Here you can also deal with rounding if you wish..
else
formatter = new DecimalFormat("0");
return formatter.format(value);
}
As you can see, if the number is natural I get - say - 20000000 instead of 2E7 (etc.) - without any decimal point.
And if it's decimal, I get only two decimal digits.