Re: Rounding Decimal Places

Sounds like a job for DecimalFormat.

Re: Rounding Decimal Places

place following piece of code after the line where you have assigned the value for monRepay

monRepay = ((initLoan * intRate) / 12) + ((initLoan / loanTerm) / 12);

double monRepayNew = rounding(monRepay,2);

totRepay = (monRepayNew * 12) * loanTerm;

System.out.println("Your monthly repayments are " + monRepayNew);

System.out.println("The total loan to be repayed over the full term of the loan is " + totRepay);

}

public static double rounding(double monRepayNew,int place){

double d = (double)Math.pow(10,place);

monRepayNew = monRepayNew * d;

double value = Math.round(monRepayNew);

return (double) value/d;

}

}

Re: Rounding Decimal Places

Use printf instead of pintln...or or or...

System.out.printf("The total loan to be repayed over the full term of the loan is %.2f \n", totRepay);

Re: Rounding Decimal Places

thanks folks, perfect, exactly what i needed!