Decimal format for another Decimal format on Android -


i'm having trouble formatting decimal value format (8487.0) format. "8.48".

i have tried solution of other issues posted here did not succeed.

example:

double n1 = double.parsedouble (string.valueof (8487.0)); decimalformat dec = new decimalformat ("#. ##"); string credits = dec.format (n1);   log.d (tag, "test" + credits); 

currently has output this: 8487

any welcomed, thanks.

you can use string format

string answer = string.format("%.2f", (8487.0 / 1000));         log.d(tag, answer); //8.49 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -