0

Rounding Doubles

This is working the way that I want, but my question is, how can I round the results to be within 2 decimal like with change? package practiceClasses; import java.util.Scanner; public class InterestCalculator { public static void main(String[] args) { Scanner input = new Scanner(System.in); double startAmount,addedInterest,originalInterest; int month = 0; System.out.println("Please input the interest amount: "); originalInterest = input.nextDouble(); System.out.println("Interest is at " + " " + originalInterest); System.out.println("Please input the orginal deposit: "); startAmount = input.nextDouble(); System.out.println("Month: " + "In Savings: " + "Added Interest: "); while(month < 12) { addedInterest = startAmount * originalInterest; startAmount = startAmount + addedInterest; month++; switch(month) { case 1: System.out.println("January " + startAmount + " " + addedInterest); break; case 2: System.out.println("Febuary " + startAmount + " " + addedInterest); break; case 3: System.out.println("March " + startAmount + " " + addedInterest); break; case 4: System.out.println("April " + startAmount + " " + addedInterest); break; case 5: System.out.println("May " + startAmount + " " + addedInterest); break; case 6: System.out.println("June " + startAmount + " " + addedInterest); break; case 7: System.out.println("July " + startAmount + " " + addedInterest); break; case 8: System.out.println("August " + startAmount + " " + addedInterest); break; case 9: System.out.println("September " + startAmount + " " + addedInterest); break; case 10: System.out.println("October " + startAmount + " " + addedInterest); break; case 11: System.out.println("November " + startAmount + " " + addedInterest); break; case 12: System.out.println("December " + startAmount + " " + addedInterest); break; }

21st Aug 2021, 8:47 PM
William Davis
William Davis - avatar
3 Antworten
0
@Martin Taylor That doesn't answer my question, I want to know how to round a double to the nearest int
25th Aug 2021, 7:49 PM
William Davis
William Davis - avatar
0
formating can also do rounding
19th Sep 2021, 5:48 AM
zemiak