Why does this integer division yield 0?

前端 未结 4 1126
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-19 14:53

Could someone tell me why the following code is outputting 0 at the marked line?

It seems as if everything is correct but then when I try to get the re

4条回答
  •  借酒劲吻你
    2021-01-19 15:31

    In short: Integer division truncates

    You need the following:

    double timeLapseInterval = (double) totalLengthSecs / (double)totalFrames;
    printf("\ntimeLapseInterval : %f \n", timeLapseInterval);
    

提交回复
热议问题