How do I prevent Double from turning a large number into exponential?

-1

I have a calculation system in my app, I use TextWatcher and when I calculate a large number and save, when I return the value, it comes in exponential (123e + 23). I already tried using bigDecimal but it gave the same error. Does anyone know what can it be? Thank you in advance.

    
asked by anonymous 03.12.2015 / 18:58

1 answer

3

One of the ways to do this is to use the String class itself.

String.format("%.0f", new BigDecimal("123e+23")); 

The output of this code is:

12300000000000000000000000

Another way to use only the BigDecimal class is:

new BigDecimal("123e+23").toPlainString();

It will produce the same output.

However, there must be a very specific case to show a number with so many digits for the user.

The number 123e + 23 is in scientific notation. It is the same as writing 123 x 10 ^ 23 or 1.23 x 10 ^ 25 or 123000000000000000000000.

    
03.12.2015 / 19:14