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:
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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.