hi, how i can convert decimal value to exponential value
A:
float x = 12313.234;
boolean neg = x < 0.0;
x *= neg ? -1 : 1;
int c = 0;
String exp;
if(x >= 1.0)
{
while(x > 10.0)
{
x /= 10.0;
c++;
}
exp = String.valueOf(x) + "e+" + String.valueOf(c);
}
else
{
while(x < 1.0)
{
x *= 10.0;
c++;
}
exp = String.valueOf(x) + "e-" + String.valueOf(c);
}
exp = neg ? ("-" + exp) : exp;
System.out.println(exp);
Amarghosh
2009-11-23 14:58:28
You sir, are a maniac.
MattC
2009-12-08 12:56:29
Yeah, now that I know that it can be done with the one liner `System.out.printf("%e\n", x);`, I can't agree more with you: I am a maniac.
Amarghosh
2009-12-09 10:01:34