Java Double Currency Format to 3 Places -
this question has answer here:
- java currency number format 16 answers
i have java android app deals tips. when take in double of bill amount , tip percent, parse them to strings display later.
how can format doubles make currency more readable @ end? instead of looking $1.0 $1.00.
the code have mentioned is:
final edittext amt = (edittext) findviewbyid(r.id.bill_amt); final edittext tip = (edittext) findviewbyid(r.id.bill_percent); final textview result = (textview) findviewbyid(r.id.res); final textview total = (textview) findviewbyid(r.id.total); double amount = double.parsedouble(amt.gettext().tostring()); double tip_per = double.parsedouble(tip.gettext().tostring()); double tip_cal = (amount * tip_per) / 100; double totalcost = amount + tip_cal; result.settext("tip amount : " + " $ " + double.tostring(tip_cal)); total.settext("total cost: " + " $ " + totalcost);
i result , total @ end outputs nicely formatted doubles 3 places. advice can give.
you can user decimalformat job you
ex
double x = 1.0; decimalformat decimalformat = new decimalformat("$#0.00"); string text = decimalformat.format(x);
[enter link description here][1]
http://docs.oracle.com/javase/7/docs/api/java/text/decimalformat.html
Comments
Post a Comment