Float is 0 after integer division

后端 未结 4 1048
Happy的楠姐
Happy的楠姐 2020-12-10 03:39

It might be a simple solution but I can not fix it.

I am dividing 2 integers :

finishedGameFinalScore = [score integerValue];
CGFloat interval = 2/fi         


        
4条回答
  •  粉色の甜心
    2020-12-10 04:29

    Just add the f-hint to the number 2. in this case that will do the trick.

    CGFloat interval = 2.0f/finishedGameFinalScore;
    

    all the above/below answers are correct and fully explain why this work.

提交回复
热议问题