나는 수업을위한 간단한 대출 계산기를 쓰고있다. 금액을 달러 형태로 반환하려고합니다. 나는 system.out.printf()를 발견했다. 그러나 제대로 작동하는 것처럼 보일 수는 없습니다. 여기 자바, 달러 값으로 두 배 형식
는 현재 코드입니다 : (나는 또한 제대로 작동하지 않습니다 알고 나중에 해결됩니다)public static void calculate() {
annualInterest = (annualInterest * 0.01)/12; //percentage to decimal then to month interest %
term = term * 12;
double payment = amtBorrowed * annualInterest;
double temp = 1/(1 + annualInterest);
temp = Math.pow(temp,term);
temp = 1 - temp;
payment = payment/temp;
double Interest = amtBorrowed * annualInterest;
double principal = payment - Interest;
System.out.println("Your monthly payment is " + payment);
System.out.println(" | Interest | principal");
System.out.println("Month 1 :" +" "+ Interest + " " + principal);
for (int i = 2; i < term + 1; i ++){
System.out.print("Month "+ i + " :");
amtBorrowed = amtBorrowed - (Interest + principal);
payment = amtBorrowed * annualInterest;
temp = 1/(1 + annualInterest);
temp = Math.pow(temp,term);
temp = 1 - temp;
payment = payment/temp;
Interest = amtBorrowed * annualInterest;
principal = payment - Interest;
System.out.println(" " + Interest + " " + principal);
}
}
출력 :
Your monthly payment is 4432.061025275802
| Interest | principal
Month 1 : 500.0 3932.0610252758024
Month 2 : 477.839694873621 3757.789681084494
Month 3 : 456.6615479938304 3591.242149217312
Month 4 : 436.4220295077747 3432.0761055985745
Month 5 : 417.079538832243 3279.9643981645363
Month 6 : 398.5943191472591 3134.594374430564
을 도움이된다면 http://vanillajava.blogspot.co.uk/2011/08/double-your-money- again.html –
두 번 사용하지 않습니까? 당신이 사용하지 않는 것을 의미합니까? 아픈 기사를 읽어 주셔서 감사합니다! – andrsnn
"double"을 사용하면 안되는 이유에 대해 누군가 의견을 말했지만 동의하지 않습니다. 대부분의 투자 은행은 BigDecimal이 아닌 long 또는 double을 사용합니다 (특히 C++에서는 esp) –