Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Having some trouble rounding decimal place

807598Jun 29 2006 — edited Jun 29 2006
Hello all,

I am having some issues rounding a decimal in my code. My program is running and doing what I would like otherwise. Here is what I have so far:
public class MortCalc2
{
	public static void main(String [] args)
	{
		//Declare and initialize three variables
		double numloanamt = 200000.00; //loan amount of 200k
		double numinterest = 0.0575;  //interest rate of 5.75%
		int numtermyrs = 30;  //term of 30 years
		int numtermmths = 360;  //term of 360 months
		double numwholeamt = 545000.00;  //loan amount + interest
		double numpayment = 0;  //monthly payment

		numpayment = numwholeamt/numtermmths;  //payment equals loan amount plus interest divided by the total term in months

		System.out.println("Your monthly payment is $" + numpayment);
	}
}
I am getting the results I want with the calculation except they are coming out as 1513.888888888889. I would like to see 1513.89. Can someone point me in the right direction. Thank you in advance for any help you can provide.

Thanks,

Seawall
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 27 2006
Added on Jun 29 2006
11 comments
132 views