BigDecimal.ROUND_HALF_DOWN
import java.math.BigDecimal;
public class Main {
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);
}
}
}
Related examples in the same category