Quantcast
Channel: Objective C ceil returns wrong value - Stack Overflow
Browsing all 4 articles
Browse latest View live

Answer by ppalancica for Objective C ceil returns wrong value

It probably evaluates 2 and 3 as integers (as they are, obviously), evaluates the result (which is 0), and then converts it to float or double (which is also 0.00000). The easiest way to fix it is to...

View Article



Answer by Tommy for Objective C ceil returns wrong value

The same rules as C apply: 2 and 3 are ints, so 2/3 is an integer divide. Integer division truncates so 2/3 produces the integer 0. That integer 0 will then be cast to a double precision float for the...

View Article

Answer by Jesse Black for Objective C ceil returns wrong value

2/3 evaluates to 0 unless you cast it to a float.So, you have to be careful with your values being turned to int's before you want.float decValue = (float) 2/3;NSLog(@"CEIL %f",ceil(decValue));==>...

View Article

Objective C ceil returns wrong value

NSLog(@"CEIL %f",ceil(2/3));should return 1. However, it shows:CEIL 0.000000Why and how to fix that problem? I use ceil([myNSArray count]/3) and it returns 0 when array count is 2.

View Article
Browsing all 4 articles
Browse latest View live




Latest Images