Mahdi Giveie
Mahdi Giveie

Reputation: 640

How to perform big numbers mathematic in Android?

I'm trying to perform this operations on two number but get NumberFormatException : invalid int : "X" how can i do this?

$hash = $orderid * 3;
$hash = $hash + 15;
$hash = $hash . $userid;
$hash = $hash - 120;
$hash = $hash / 5;
$hash = $hash . $userid;
$hash = $hash - 174;

suppose order id is 1426518618 and userid is 9965

EDIT : this is php code but there is no difference between this and java except (.) thing! this means two number will be add to each other for example x = 22 and y = 33 then x.y mean 2233

this is my code which i get error:

    private String getHash(){
    long hash = 0;

    try{
    hash = (Integer.parseInt(mOrderID))*3;
    hash = hash +15;        
    String temp = String.valueOf(hash);
    hash = Integer.parseInt(temp+MyAccountAdapter.mEditItems.getID());
    hash = hash -120;
    hash = hash / 5;
    temp = String.valueOf(hash);
    hash = Integer.parseInt(temp+MyAccountAdapter.mEditItems.getID());
    hash = hash -174;
    } catch(NumberFormatException e){
        e.printStackTrace();
    }
    return String.valueOf(hash);
}

thank you in advanced

Upvotes: 0

Views: 764

Answers (1)

peresisUser
peresisUser

Reputation: 1686

You can probably use long. It's size is 2^64-1.. You can read more Here: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html You use Integer.parseInt() when you should use Long.parseLong(). Integer is the wrapping class for the primitive int and Long is for the primitive long. Read some more here: way2java.com/java-lang/wrapper-classes

Upvotes: 1

Related Questions