Division with expected result between 1 and 0 always gives 0 [duplicate]
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: What is the behavior of integer division in C? When I do a division calculation with an answer that's supposed to be between 1 and 0, it always returns 0. Try this: float a = 1; float b = 2; float c = a / b; //variable divide by variable gives 0.5 as it should float d = 1 / 2; //number divide by number gives 0 float e = 4 / 2; NSLog(@"%f %f %f %f %f", a,b,c, d, e); I get this from the console: 2013-01-17 14:24