当我为月利率和1年的投资金额4.25输入1000时,为什么我得到的结果是4.384414858452464E11而不是预期的1043.34?
import java.util.Scanner;
public class FinancialApplicationFutureInvestment_13 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter investment amount: ");
int investmentAmount = input.nextInt();
System.out.println("Enter monthly interest rate: ");
double monthlyInterestRate = input.nextDouble();
System.out.println("Enter number of years");
int numOfYears = input.nextInt();
double futureInvestmentValue = investmentAmount *
(Math.pow(1 + monthlyInterestRate, numOfYears * 12));
System.out.println("Accumulated value is: " + futureInvestmentValue);
double test = Math.pow(1 + monthlyInterestRate, numOfYears * 12);
System.out.println(test);
}
}
答案 0 :(得分:5)
每月利率可能需要输入0.0425
答案 1 :(得分:2)
1 + monthlyInterestRate
monthlyInterestRate
是原始因素,还是以百分点表示?
尝试除以一百。
答案 2 :(得分:2)
公式是
A = P(1+r/100)^n
所以它应该是
investmentAmount * (Math.pow(1 + (monthlyInterestRate/100), numOfYears * 12));
答案 3 :(得分:2)
好吧,你计算1 + 4.25(5.25)作为月利率,而不是1 +(4.25 / 100)。
答案 4 :(得分:1)
你应该在System.out.println中使用强制转换(double to int) - (int)(futureInvestmentValue * 100)/ 100.0