Possible Duplicate:
C problem – division result is always zero
I’m trying to get my head around how objective C works, Can anyone explain what I’m doing wrong?
double hr = ((1/360) * 300);
NSLog(@"%f", hr);
returns:
2012-06-06 14:07:02.511 Clock2[3385:f803] 0.000000
Thanks in advance
C and related languages such as C++ and Objective C use integer (truncating) division when both LHS and RHS are integers, so 1 / 360 = 0. For floating point arithmetic try to get into the habit of using floating point literals, even for whole numbers, i.e. change:
to: