Compare floats in php

后端 未结 16 1674
清歌不尽
清歌不尽 2020-11-22 00:47

I want to compare two floats in PHP, like in this sample code:

$a = 0.17;
$b = 1 - 0.83; //0.17
if($a == $b ){
 echo \'a and b are same\';
}
else {
 echo \'a         


        
16条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 01:19

    Or try to use bc math functions:

    Result:

    0.17 == 0.17 (core comp oper): bool(false)
    0.17 == 0.17 (with bc func)  : bool(true)
    

提交回复
热议问题