doushi8231 2014-08-12 22:16
浏览 46
已采纳

php使用类型转换将float转换为int

So I am reading the php manual on its types and am playing around with them. I have:

var_dump((int)0.8 + 0.2)

why does this return 0.2?

I have no idea why.

  • 写回答

1条回答 默认 最新

  • dongshan4518 2014-08-12 22:17
    关注

    It first evaluates (int)0.8, which is 0, then it adds 0.2. You need to use,

    var_dump((int)(0.8 + 0.2))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?