【问题标题】:Why converting to integer first when converting from any type except string to float?从字符串以外的任何类型转换为浮点数时,为什么要先转换为整数?
【发布时间】:2014-10-08 12:56:18
【问题描述】:

有关将strings 转换为float 的信息,请参阅String conversion to numbers。对于其他类型的值,转换是先转换成integer再转换成float。

http://php.net/float

为什么要先转换成整数型,再转换成浮点型?

【问题讨论】:

    标签: php floating-point integer int type-conversion


    【解决方案1】:

    只有字符串可以包含类似浮点的值。或者array() 的浮点值是多少?还是resource?因此,将转换为int 的规则应用于这些值,因为这些规则已经存在并已定义。无需为所有类型的浮点数重复这些转换规则;只需应用int 规则,然后转换为float

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-25
      • 1970-01-01
      • 2016-11-23
      • 2011-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多