import java.math.BigDecimal;
import java.text.NumberFormat;
public class Example {
public static void main(String[] args) {
BigDecimal amount = new BigDecimal("10000.56");
BigDecimal tax = new BigDecimal("0.15");
BigDecimal salesTax = amount.multiply(tax);
salesTax = salesTax.setScale(2, BigDecimal.ROUND_HALF_UP);
BigDecimal total = amount.add(salesTax);
NumberFormat currency = NumberFormat.getCurrencyInstance();
String s = "Amount: " + currency.format(amount) + "\n" +
"Tax: " + currency.format(salesTax) +
"\n" + "Total: " + currency.format(total) + "\n";
System.out.println(s);
}
}
/*
run:
Amount: $10,000.56
Tax: $1,500.08
Total: $11,500.64
*/