0

i have a double value Such as

Double doubleValue=0.0001;

trying to print this gave me an output as 1.0E-4

So I tried BigDecimal to value of this as.

BigDecimal.valueOf(doubleValue) which ended up giving output as "0.00010".

can anyone let me know how would I get a round up value as "0.0001".( no end trail of 0 after 1)

azurefrog
  • 10,785
  • 7
  • 42
  • 56
Kumar
  • 183
  • 1
  • 12

2 Answers2

1

You can try code similar to following

Double doubleValue=0.0001;    
DecimalFormat f = new DecimalFormat("##.0000");
String formattedValue = f.format(doubleValue);
BigDecimal bigDecimalValue = new BigDecimal(formattedValue);
bigDecimalValue.stripTrailingZeros();

Hope this helps

Balwinder Singh
  • 2,272
  • 5
  • 23
  • 34
1

Are you printing with println? You should use printf to format your output.

        Double d = 0.000100;
        System.out.printf("%.4f",d);    

The following will print "0.0001"

Hope this helps!

Archytekt
  • 21
  • 2