Created
May 17, 2019 15:45
-
-
Save avermeulen/e12023636ae4a7ec5e1e6f50c4690fb6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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