Kevin_Coors
asked on
Rounding off Java numbers
Hello
Could someone please run my programme below and tell me how I can round off the double values to 2 decimal places
Many thanks
/*4. Write a program to calculate and display the amount of money in a bank
account that was opened with a deposit of €20 fifteen years ago and has
earned interest at 10% (compound interest) per annum. Your program
should display the amount of money in the account at the end of each year
for all of the 15 years.*/
Could someone please run my programme below and tell me how I can round off the double values to 2 decimal places
Many thanks
/*4. Write a program to calculate and display the amount of money in a bank
account that was opened with a deposit of €20 fifteen years ago and has
earned interest at 10% (compound interest) per annum. Your program
should display the amount of money in the account at the end of each year
for all of the 15 years.*/
public class Q4
{
public static void main (String [] args)
{
double start = 20;
double years = 15;
double interest = 10;
double totalInt;
for (int counter = 1; counter <=15; counter ++)
{
totalInt = (start / 100) * interest;
start = start + totalInt;
System.out.println("Year " + counter + " Total €" + start);
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Open in new window