Skip to content

Instantly share code, notes, and snippets.

@avermeulen
Created May 17, 2019 15:45
Show Gist options
  • Save avermeulen/e12023636ae4a7ec5e1e6f50c4690fb6 to your computer and use it in GitHub Desktop.
Save avermeulen/e12023636ae4a7ec5e1e6f50c4690fb6 to your computer and use it in GitHub Desktop.
package net.greet.web;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class CompoundInterest {
public static void main(String[] args) {
double pv = 28000;
double interestRate = 7/100d;
System.out.println(interestRate);
int years = 6;
double totalInterest = pv * Math.pow((1 + interestRate/12), years*12);
double roundedValue = new BigDecimal(totalInterest)
.setScale(2, RoundingMode.HALF_EVEN)
.doubleValue();
System.out.println(roundedValue);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment