📜  比较浮动 php 代码示例

📅  最后修改于: 2022-03-11 14:54:41.927000             🧑  作者: Mango

代码示例1
// You cannot compare float values like you would compare intergers in PHP
// since a float is calculated and may not have the exact value as shown
// an easy way to get around this is to round the float, then convert the float
//to a string for the comparison
$a = 1.5;
$b = 1.5;
$a = round($a, 2);
$b = round($b, 2);
if (strval($a) === strval($b)) var_dump('it matches!');