문제

I'm trying to output a really simple value, but what I obtain is really weird:

Log.d("try", "distanceWithMaxSpeed > " + ((90 * (1000 / 3600)) * ((3000 - 2000)/1000)) );

I get 0 instead of 25! Where am I wrong?

도움이 되었습니까?

해결책

Integer Division

1000/3600 = 0

You should change them to floats (90f) or doubles (90.0)

다른 팁

You're doing integer division. If the numerator is less than the divisor, then at least one of the operands should be a double:

Log.d("try", "distanceWithMaxSpeed > " + ((90 * (1000.0 / 3600)) * ((3000 - 2000)/1000)) );
                                                     ^^
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top