Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图输出一个非常简单的值,但我得到的真的很奇怪:
Log.d("try", "distanceWithMaxSpeed > " + ((90 * (1000 / 3600)) * ((3000 - 2000)/1000)) );
我得到 0 而不是 25!我哪里错了?
整数除法
1000/3600 = 0
您应该将它们更改为浮点数 ( 90f) 或双精度数 ( 90.0)
90f
90.0
你正在做整数除法。如果分子小于除数,则至少有一个操作数应该是 a double:
double
Log.d("try", "distanceWithMaxSpeed > " + ((90 * (1000.0 / 3600)) * ((3000 - 2000)/1000)) ); ^^