BigDec.java Source code

Java tutorial

Introduction

Here is the source code for BigDec.java

Source

import java.math.BigDecimal;

public class BigDec {
    public static void main(String args[]) {
        BigDecimal rate = new BigDecimal(".03251234");
        BigDecimal months = new BigDecimal("12");
        BigDecimal monthlyRate = rate.divide(months, BigDecimal.ROUND_HALF_DOWN);
        System.out.println("Annual rate : " + rate);
        System.out.println("Monthly rate: " + monthlyRate);
        BigDecimal balance = new BigDecimal("10000.0000");
        for (int i = 0; i < 12; i++) {
            BigDecimal interest = balance.multiply(monthlyRate);
            balance = balance.add(interest);
            System.out.println("Balance: " + balance);
        }
    }
}