开发者

Android java using Eclipse math, I don't know why simple math is coming up with wrong result?

开发者 https://www.devze.com 2023-04-13 04:25 出处:网络
I have four variables with the following values (I am sure about the values they have): 15 100 1 4000 I am trying to output the values into a toast message, but they are coming up wrong.

I have four variables with the following values (I am sure about the values they have):

15
100
1
4000

I am trying to output the values into a toast message, but they are coming up wrong.

Here is what I did:

Toast.makeText( TreActivity.this,
                String.valueOf( ((15 + 100) * 10) + 4000 ),
                Toast.LENGTH_SHORT ).sho开发者_JAVA技巧w();

When testing this in the emulator, it comes up as 14150. This is wrong, because ((15+100)*10)+4000 = 5150.

I must be missing something special with Android/Java in the way things are calculated.

Any help is much appreciated!


Dont do String.valueOf(...) just try your calculation and then at the end put +"" to make it a string. See what that does

UPDATE:

If the problem isnt fixed yet you should try breaking the equasion down to see where the issue is. you should add 100 and 15 together and just put 150 and then just keep doing that untill you see where the issue is. It might be that you have a parenthases out of place.

0

精彩评论

暂无评论...
验证码 换一张
取 消