I have things object called – bombObject, which has a float property called ‘blastRadius’.
When ‘NSLog(@”%.2f”,bombObject.blastRadius);’ executes I get whatever i made it in the first pace e.g. 100 etc. But if execute: ‘NSLog(@”%.2f”,bombObject.blastRadius*(3/7));’ I don’t get 3/7 of the blastRadius, I get 0.00. However if i do ‘NSLog(@”%.2f”,(bombObject.blastRadius*3)/7);’ I get the desired answer.
Why is this?
Thanks in advanced!
An int/int will not promote to a float, so you end up with only an integer being returned. 3/7 is less than 1 so you end up truncating to 0. You then multiply bombObject.blastRadius by 0 which gives you the 0.00 answer you are seeing.
Why does (bombObject.blastRadius*3)/7 work though? Because bombObject.blastRadius*3 is a float resultant; a float / int would become a float which is why it works in this instance.