-1

I've got a problem here, when I calculate a figure of more than 2 billion and 3 billion are always error and displays the force close. So what I need to fix it

long  initial_investment, total_investment;
 DecimalFormat df = new DecimalFormat ("###,###,###,###");
initial_investment = Integer.parseInt( Text1.getText().toString());


if (initial_investment <= 1000000000)
                 {

                     total_investment = ((initial_investment * 3) /100)+ total_investment;
                     Text5.setText(df.format(total_investment));

                 }
                 else if (initial_investment > 1000000000 && initial_investment <= 3000000000L )
                 {

                     total_investment = (long) (((initial_investment* 2.5) /100)+ total_investment);
                     Text5.setText(df.format(total_investment));

                 }
                 else if (initial_investment > 3000000000L )
                        {

                        total_investment = ((initial_investment * 2) /100)+ total_investment;
                        Text5.setText(df.format(total_investment));

                        }

            }
Ricky AN
  • 1
  • 3

3 Answers3

2

I would suggest you to use BigInteger if you are dealing with some very large value. You can use it as shown below

BigInteger bi1, bi2, bi3;  

// assign values to bi1, bi2
bi1 = new BigInteger("123");
bi2 = new BigInteger("50");

// perform add operation on bi1 using bi2
bi3 = bi1.add(bi2);

String str = "Result of addition is " +bi3;
S4beR
  • 1,872
  • 1
  • 17
  • 33
0

You could do something like

initial_investment= Long.parseLong( Text1.getText().toString());

instead of

initial_investment = Integer.parseInt( Text1.getText().toString());
Yair Kukielka
  • 10,686
  • 1
  • 38
  • 46
0

Sorry this is my fault, but now I've had to fix it I just need to change initial_investment from int to an long

initial_investment = Long.parseLong( Text1.getText().toString());
Ricky AN
  • 1
  • 3