Code
package Java.School.IX;
import java.util.*;
public class Invest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter principle - Rs ");
double p = sc.nextDouble();
//Interest for 1st yr -
double i1 = (p*3*5)/100;
double a = Math.round(i1,2);
System.out.println("Interest for 1st year is Rs " + a);
//Interest for 2nd yr -
double p1 = p + i1;
double i2 = (p1*3*5)/100;
System.out.println("Interest for 2nd year is Rs "+ i2);
sc.close();
}
}
Issue
I tried using Math.round(double, noOfPlaces)
, but this code doesn't seem to be working. I need some guidance.
Pls help me to round of the decimal to 2 decimal places. How to fix this?