afb afb - 1 year ago 111
Android Question

Show very big double values on EditText

First of all please excuse me for my bad English speaking.

I am new to Android Development. I have a problem and think you can solve it.

The problem is:

I have a very big double value like

in my android app
but when i want to show it on
, it will be shown like this
In this case when my value characters is over than 15 chars android shows remaining chars with "0"

i don't know what i have to to do.

i am using this code:

DecimalFormat df = new DecimalFormat("#.#########");
double a = Distancevals[1] * Distancevals[2];
//Distancevals is an array of double with big values
EditText editto = (EditText)findViewById(...);

Answer Source

Double stores your number 12345678987654321 in format 1.23456789876543E16, so you lose the end of the number 21. When you format the result it's known that your number consists of 17 signs, so format function adds two zeros in the end of your number instead of 21.

Try to use this:

DecimalFormat df = new DecimalFormat("#.#########");
BigDecimal a = new BigDecimal(Distancevals[1] * Distancevals[2]);
// Distancevals is an array of double with big values
EditText editto = (EditText) findViewById(...);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download