【问题标题】:php converting float to int using type castingphp使用类型转换将float转换为int
【发布时间】:2014-10-06 03:41:38
【问题描述】:

所以我正在阅读有关其类型的 php 手册并正在玩弄它们。我有:

var_dump((int)0.8 + 0.2)

为什么会返回0.2?

我不知道为什么。

【问题讨论】:

    标签: php floating-point int type-conversion


    【解决方案1】:

    它首先计算(int)0.8,即0,然后加上0.2。你需要使用,

    var_dump((int)(0.8 + 0.2))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-15
      • 2012-05-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多