I got a Problem which I think is easy to solve but I can’t find an answer:
long test = 8064269 / 8300000;
NSLog(@"%lu",test);
The Log is giving me:
0 (should be something near to 1)
I need to do a little more math with this later and then it is:
long test = 8064269 / 8300000 * 277;
NSLog(@"%lu",test);
The Log is giving me:
4294967048 (should be something near to 277)
What am I doing wrong?
is an integer division as all the operands are integral types. That is, it truncates the fractional part and leaves only the integer part that is 0.
But even if this wasn’t the case, how do you expect to store a fractional number in an integer (in a
long)? Assigning to an integer, again, also truncates the result. In first place, you need