【问题标题】:PHP Double comparisionPHP 双重比较
【发布时间】:2019-01-10 04:11:29
【问题描述】:

PHP 版本 7.1.7 / Laravel 5.4

dump($this_tour->payments_to_operator_sum());

1012.0

dump(gettype($this_tour->payments_to_operator_sum()));

“双”

dump($this_tour->operator_price, gettype($this_tour->operator_price));

“1012.00”,“字符串”

dump((double)$this_tour->operator_price, gettype((double)$this_tour->opeartor_price);

1012.0,“双”

dump($this_tour->payments_to_operator_sum() == (double)$this_tour->operator_price);

为什么会是假的?

我很困惑。

PS。我理解“==”和“===”之间的区别,我想这与它无关。 当我这样做时:

dump((double)1012.0 == (double)"1012.00"); 

我明白了

是的

【问题讨论】:

    标签: php double comparison equality php-internals


    【解决方案1】:

    当我这样做时:

    return $this_tour->payments_to_operator_sum()
    

    (而不是“转储”),我得到了:

    1011.9999999999999

    我猜这就是答案。

    【讨论】:

      猜你喜欢
      • 2012-10-09
      • 2011-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-08
      • 1970-01-01
      • 1970-01-01
      • 2022-08-02
      相关资源
      最近更新 更多