Scanner sc = new Scanner(System.in);
System.out.println("Enter Name : ");
String name = sc.nextLine();
System.out.println("Enter Id : ");
int id = sc.nextInt();
System.out.println("enter salary per day : ");
double d = sc.nextDouble();
// to show 0 decimals in double value after decimal floating-point values don't have decimal //digits. They have binary digits.
BigDecimal b = new BigDecimal(Double.toString(d));
b = b.setScale(2, BigDecimal.ROUND_HALF_UP);
System.out.println("Details :"+name+"\n"+id+"\n"+b);
System.out.println("Enter Name : ");
String name = sc.nextLine();
System.out.println("Enter Id : ");
int id = sc.nextInt();
System.out.println("enter salary per day : ");
double d = sc.nextDouble();
// to show 0 decimals in double value after decimal floating-point values don't have decimal //digits. They have binary digits.
BigDecimal b = new BigDecimal(Double.toString(d));
b = b.setScale(2, BigDecimal.ROUND_HALF_UP);
System.out.println("Details :"+name+"\n"+id+"\n"+b);
No comments:
Post a Comment