double d = 1.999e-4;
NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits(7);
System.out.println(nf.format(d));
Check out the documentation of NumberFormat's methods to format your double as you see fit.
DecimalFormat is a special case of NumberFormat as its constructor states, I don't think that you need its functionality for your case. Check out their documentation if you are confused. Use the factory method getInstance() of NumberFormat for your convenience.
You can do it like this:
Check out the documentation of
NumberFormat
's methods to format yourdouble
as you see fit.DecimalFormat
is a special case ofNumberFormat
as its constructor states, I don't think that you need its functionality for your case. Check out their documentation if you are confused. Use the factory methodgetInstance()
ofNumberFormat
for your convenience.I suppose there is a method in BigDecimal Class called
toPlainString()
. e.g. if the the BigDecimal is 1.23e-8 then the method returns 0.0000000124.Above code prints 0.0000000123, then you can process the string as per your requirement.
Take a look over
and
If all you want is to print like that.
you can change 10f, 10=number of decimal places you want.
You can explore the sub classes of
NumberFormat
class to know more details.