public class Calc2 {
public static void main(String args[]) {
BigDecimal amount = new BigDecimal("100.05");
BigDecimal discountPercent = new BigDecimal("0.10");
BigDecimal discount = amount.multiply(discountPercent);
discount = discount.setScale(2, RoundingMode.HALF_UP);
BigDecimal total = amount.subtract(discount);
total = total.setScale(2, RoundingMode.HALF_UP);
BigDecimal taxPercent = new BigDecimal("0.05");
BigDecimal tax = total.multiply(taxPercent);
tax = tax.setScale(2, RoundingMode.HALF_UP);
BigDecimal taxedTotal = total.add(tax);
taxedTotal = taxedTotal.setScale(2, RoundingMode.HALF_UP);
System.out.println("Subtotal : " + amount);
System.out.println("Discount : " + discount);
System.out.println("Total : " + total);
System.out.println("Tax : " + tax);
System.out.println("Tax+Total: " + taxedTotal);
}
}
http://www.yunsobi.com/blog/227
http://hangaebal.blogspot.kr/2014/06/javamathbigdecimal-discount-tax.html
'Blogger 이사' 카테고리의 다른 글
[Node.js] Error connection lost the server closed the connection (0) | 2016.01.14 |
---|---|
[Spring] Spring web 프로젝트 준비 (Eclipse, Gradle) (0) | 2016.01.14 |
[JavaScript] JavaScript get Object Length (0) | 2016.01.14 |
[jQuery UI] Touch Event Support for jQuery UI (draggable 등 mobile device에서 사용하기) (0) | 2016.01.14 |
[MyBatis] MyBatis 기본 (0) | 2016.01.14 |