Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java BigDecimal without E

I have a BigDecimal variable

BigDecimal x = new BigDecimal("5521.0000000001");

Formula:

x = x.add(new BigDecimal("-1")
      .multiply(x.divideToIntegralValue(new BigDecimal("1.0"))));

I want to remove the integer part, to get the value x = ("0.0000000001"), but my new value is 1E-10 and not the 0.0000000001.

like image 980
user1609993 Avatar asked Aug 19 '12 12:08

user1609993


People also ask

How do you avoid exponential formatting in Java?

toString() : Double class comes with an inbuilt method toString() method to convert a double value to string. It will not add any exponential component to the conversion.

Can a BigDecimal be negative?

The value of the BigDecimal is (BigInteger/10**scale). A negative scale will result in a NumberFormatException.

What is E in double value?

In scientific notation, the letter E is used to mean "10 to the power of." For example, 1.314E+1 means 1.314 * 101 which is 13.14 . Scientific notation is merely a format used for input and output. The 64-bit pattern used for a double inside the computer are the same, no matter what character format was used for input.


1 Answers

Try using BigDecimal.toPlainString() to get value as plain string as you require.

like image 136
Akhilesh Awasthi Avatar answered Sep 29 '22 12:09

Akhilesh Awasthi