I have a Java Android app that deals with tips. When I take in the double of bill amount and tip percent, I parse them to to strings to display later.
How can I easily format the doubles to make the currency more readable at the end? Instead of looking like $1.0 it would be $1.00.
The code I 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 would like result and total at the end to be the outputs that are nicely formatted doubles to 3 places. Thanks for any advice you can give.