임씨는 수업을위한 대출 계산기를하고 있습니다. 나는 거의 끝났지 만 실종 된 유일한 방법은 $ 298.95833333333337 대신 INTEREST_RATE를 반올림하는 방법입니다. $ 298.96을 얻고 싶습니다. 하지만 어떻게해야할지 모르겠다. 이전 원리를 입력학교 프로젝트, 가장 가까운 센트로 두 배 증가.
=
현재 지불을 입력 =
이전 밸런스 : $ 25000.0
지불 : $ 450.0
유료 관심 : $ 151.04166666666666
원리 유료 : $ 298.95833333333337
신규 사용자 : $ 24701.041666666668
import java.util.Scanner;
public class LoanCalculator {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
/**
* Declaration Section
*
*/
Scanner keyboard = new Scanner(System.in);
double INTEREST_RATE;
double currentPayment;
double oldPrincipal;
double interestPaid;
double principalPaid;
double newPrincipal;
/**
* Process Section
*
*/
System.out.println("Enter your old Principle = ");
oldPrincipal = keyboard.nextDouble();
System.out.println("Enter your current payment = ");
currentPayment = keyboard.nextDouble();
INTEREST_RATE = 7.25/100.0; //fix this
interestPaid = oldPrincipal * INTEREST_RATE/12;
principalPaid = currentPayment - interestPaid;
newPrincipal = oldPrincipal - principalPaid;
/**
* Output Section
*
* */
System.out.println("Previous Balance: " + "$"+ oldPrincipal);
System.out.println("Payment: " + "$"+ currentPayment);
System.out.println("Interest Paid: " + "$"+ interestPaid);
System.out.println("Principle Paid: " + "$"+ principalPaid);
System.out.println("New Principal: " + "$"+ newPrincipal);
}//Main()
}//LoanCalculator
가능한 중복을 [ 자바에서 두 자릿수] (http://stackoverflow.com/questions/5710394/round-double-to-two-decimal-places-in-java) – Casey
나는 가장 가까운 페니로 돌리고 싶다. 그리고 지금까지 우리는 BigDecimal에 관해서 배웠다. –
@DacoApps cxdm이 질문 한 내용을 본 적이 있는가? BigDecimal은 학업 성향을 보이기 때문에 사례에서 큰 차이를 만들지 못할 수 있습니다. 검색 Fu에서 작업해야합니다. 혼자서도 답을 찾으려고 노력할 때 많은 시간을 소비 할 수 있습니다. – MarsAtomic