I have a very small number and I want to convert it to a String with the full number, not abbreviated in any way. I don't know how small this number can be.
for example, when I run:
double d = 1E-10;
System.out.println(d);
it shows 1.0E-10
instead of 0.000000001.
I've already tried NumberFormat.getNumberInstance()
but it formats to 0
. and I don't know what expression to use on a DecimalFormat
to work with any number.
Using the “+” operator − The + operator is an addition operator but when used with Strings it acts as a concatenation operator. It concatenates the other operand to String and returns a String object. You can convert a double value into a String by simply adding it to an empty String using the “+” operator.
Assuming that you want 500 zeroes in front of your number when you do:
double d = 1E-500;
then you can use:
double d = 1E-10;
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(Integer.MAX_VALUE);
System.out.println(nf.format(d));
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