System.out.println(2e+5);
Above line's output is,
200000.0
While below line's,
System.out.println(2e-5);
output is,
2.0e-5
Why does 2e-5
is not solved down with -10^5
giving the output,
0.00002
Because that's how the designers of the Double class chose to implement it:
[...]
- If m is greater than or equal to 10-3 but less than 107, then it is represented as the integer part of m, in decimal form with no leading zeroes, followed by '.' ('\u002E'), followed by one or more decimal digits representing the fractional part of m.
- If m is less than 10-3 or greater than or equal to 107, then it is represented in so-called "computerized scientific notation." [...]
They could have made another choice, of course, but that's simply how it is.
As the documentation says, if you want a specific format, use a NumberFormat
to format your double.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With