Home > Back-end >  Calculate how Banks earn interest income to ask ah how get (num - sum1) into two decimal places?????
Calculate how Banks earn interest income to ask ah how get (num - sum1) into two decimal places?????

Time:09-25

The import com. Sun. XML. Internal. Ws. API. Pipe. SyncStartForAsyncFeature;

import java.util.Scanner;

Public class bank
{
Public static double interest=2.65;//interest
Public void rise ()
{
Interest=interest + 0.5;
}
Public static void main (String [] args)
{
Bank pool=new bank ();
System. The out. Println (" the current interest rates for bank death "+ interest +" % ");
System. The out. Println (" please enter the deposit ");
Scanner sc=new Scanner(System.in);
Double num=sc. NextDouble ();
System. The out. Println (" please enter the deposit term ");
Double year=sc. NextDouble ();
Double sum1=num;
For (int I=1; i<=year; I++)
{
Num=num + ((num/100) * 2.65);
}
System. The out. Println (" five years later, in 20000 dollars for that obtained "+ (num - sum1));
}

}

CodePudding user response:


Public class T6 {

Public static void main (String [] args) {

Double x1=1.126;

System. Out. Println (the String. Format (. % 2 f, the x1));

DecimalFormat df=new DecimalFormat (" 00 ");

System. The out. Println (df) format (x1));

}

}

CodePudding user response:

The String. Format (" % 2 f ", num - sum1)

But easy to lose accuracy was calculated by the int directly, suggest using Bigdecimal

CodePudding user response:

Ok, Bigdecimal is???

CodePudding user response:

reference Lin_bai_ reply: 3/f
ok, Bigdecimal is???


Addition of the add ()
Subtract () by subtracting the
Multiply is multiplied by ()
Divide () by

All arithmetic operation is a method of operation will be more precise
  • Related