Why does this integer division yield 0?

前端 未结 4 1128
爱一瞬间的悲伤
爱一瞬间的悲伤 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:12

    You are performing integer math.

    Math between two integers will produce an integer. And the result will be rounded towards zero.

    This line:

    totalLengthSecs / totalFrames;
    

    Is likely producing a result that's between 0 and 1. And getting rounded to 0

提交回复
热议问题