简体   繁体   English

Java计算奇怪的结果

[英]Java Calculation strange result

This is the calculation I want my app to calculate:这是我希望我的应用计算的计算:

100000000*90/100

Expected result: 90000000预期结果: 90000000

Javas result: 4100654 Javas 结果: 4100654

Why is it doing this?为什么要这样做? The first number (100000000) is coming from an int array and its written into a textView.第一个数字 (100000000) 来自一个 int 数组并将其写入 textView。

Im trying to get 90% of 100000000.我试图获得 100000000 的 90%。

I tried the following:我尝试了以下内容:

    long test123 = 100000000*90/100;
    Log.i("test123", String.valueOf(test123));

If you want to do this operation you should use long or multiply by 90L that will force answer to be a long.如果您想执行此操作,您应该使用 long 或乘以90L ,这将强制答案为 long。 As @Nicolas pointed out by doing 100000000 * 90 you hit max int value hence the result.正如@Nicolas 通过执行100000000 * 90指出的那样,您达到了最大 int 值,因此得到了结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM