|
-
Jan 18th, 2009, 09:51 AM
#1
Thread Starter
New Member
round down to 2 sig. numbers after the decimal point
I would like to round my number down to 2 sig. numbers after the decimal point in my answer, ie:
Old loan: £745.09
Loan plus 3% interest: £767.44
Wages: £19,206.92
Wages minus threshold: £9,206.92
Repayment: £828.62
New loan amount: £-61.18
at the moment my answer is:
Loan plus 3% interest: 767.4417386951634
wages: 19206.920769257813
Wages minus threshold:9206.920769257813
Amount Re-paid: 828.6228692332031
New loan amount: -61.181130538039724
public class loanPayments {
// place constant declarations (static final) below.
// e.g. 3% interest, 9% repayment, 5% pay rise and 10k theshold
public static void main (String[]arg){
//declare variables
double loan;
double wages;
final int THRESHOLD= 10000;
double netInc=0;
double newBal=0;
double totalLoan;
double deduction;
double firstBal;
int year=1;
//print qoute
System.out.println("Enter total amount of student loan taken");
loan=UserInput.readDouble();
//print qoute
System.out.println("Enter anticipated income");
wages=UserInput.readDouble();
firstBal = newBal-0;
while (newBal >= 0) {
newBal=loan*0.03;
netInc=wages-THRESHOLD;
deduction=netInc*0.09;
totalLoan=loan+newBal;
newBal=totalLoan-deduction;
System.out.println("Year: "+year+" Old loan: £"+loan);
System.out.println("Loan plus 3% interest: £" +totalLoan);
System.out.println("wages: "+wages);
System.out.println("Wages minus threshold: £" +netInc);
System.out.println("Amount Re-paid: £"+ deduction);
System.out.println("New loan amount: £"+newBal);
loan=newBal+0;
wages=wages +(wages*0.05);
year=year+1;
}
year=year-1;
System.out.println("It took you "+year+" years to repay the loan");
System.out.println("The original loan was "+firstBal+" but you had to pay back £4,801.08");
}//end main
}//end class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|