代码之家  ›  专栏  ›  技术社区  ›  Sergej Fomin

PHP双比较

  •  -1
  • Sergej Fomin  · 技术社区  · 6 年前

    PHP 7.1.7版 /拉斐尔5.4

    dump($this_tour->payments_to_operator_sum());
    

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

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

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

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

    我很困惑。

    我明白“==”和“==”之间的区别,我想这与它无关。 当我这样做的时候:

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

    我明白了

    1 回复  |  直到 6 年前
        1
  •  1
  •   Sergej Fomin    6 年前

    return $this_tour->payments_to_operator_sum()
    

    1011.9999999999999

    我想这就是答案。