Question

Following the format below..

System.out.printf("%.2f", val);

Was wondering how i could get my output to be 2 decimal places to the left side not to the right? I am trying to compute monthly interest rate. My formula in my class method is:

  • Annual Rate is set at 4.5 it cannot be changed so i have it set to: private static in my separate class.
  • Formula for monthlyInterest return (annualInterestRate / 12) * balance;

Then when i go back to main and try and print as follows: "\nAnnual Rate:\t" + String.format("%.2f", a.getAnnualRate())

Results

ID:       1122
Created:      03/02/14
Owner:        Tom H
Opening Balance:  $100.0
Annual Rate:      4.50
Monthly Interest: 37.5 <-----Would like this to display the monthly interest properly

No correct solution

OTHER TIPS

Yes, you can format your output either by using System.out.printf() or by using System.out.format().

Monthly Interest: 37.5 <-----Would like this to display the monthly interest properly  

Now, in comments you mention 0.375 and then you show 37.5 here. Surly, the unit in which the value is represented will change, bear that in mind.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top