-5

This is what I have:

if (balance * 100 % 10 == 0) {
    balance = balance + 0.00;
}
if (balance > 0) {
    return name + ", $" + balance;
} else if (balance < 0) {
    return name + ", -$" + -balance;
} else { // balance = 0
    return name + ", $0.00";
}

I want to return "$4.80" but I keep getting "$4.8". How do I get the 0 at the end of the decimal?

amber
  • 1

1 Answers1

0

You can use Java's NumberFormat or DecimalFormat, specifically there is a getCurrencyInstance http://docs.oracle.com/javase/6/docs/api/java/text/NumberFormat.html#getCurrencyInstance()

keyser
  • 18,829
  • 16
  • 59
  • 101
Jeff Storey
  • 56,312
  • 72
  • 233
  • 406