Search code examples
javabigdecimal

How Can I perform Addition on Big Decimal?


I have Column in Database which has value stored in this format "0.0000000000" I need to retrieve this value from database and perform Add operation to this value like "0.000000000000 + 0.0000000001" How can I print the whole value as output in console? And Is is possible to convert the output into String format?


Solution

  • Looks like you are trying to avoid 1E-10 expression you can do that as

    BigDecimal bigD = new BigDecimal("0.0000000000").add(new BigDecimal("0.0000000001"));
    System.out.println(bigD.toPlainString());