if
double d = 1.999e-4
I want my output to be 0.0001999.
How can I do it?
The format of scientific notation in Java is exactly the same as you have learned and used in science and math classes. Remember that an uppercase 'E' or lowercase 'e' can be used to represent "10 to the power of". Scientific notation can be printed as output on the console if it passes a certain number.
b is the power of 10 required so that the scientific notation is mathematically equivalent to the original number. Move the decimal point in your number until there is only one non-zero digit to the left of the decimal point. The resulting decimal number is a. Count how many places you moved the decimal point.
NumberFormat formatter = new DecimalFormat("###.#####");
String f = formatter.format(d);
You can explore the sub classes of NumberFormat
class to know more details.
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