Floating point arithmetic:
$f = 1234567890123456789.0;
$s = (string)$f;
echo(serialize($f));
echo "\n";
echo(serialize($s));
d:1.2345678901234568E+18;
s:19:"1.2345678901235E+18";
質問
Can someone explain why it's not possible to compare big floating point numbers with it's string equivalent:
This example:
$f = 1234567890123456789.0;
$s = (string)$f;
var_dump($f, $s, $f == $s);
will result in:
float(1.2345678901235E+18)
string(19) "1.2345678901235E+18"
bool(false)
Why the comparison is false?
解決
Floating point arithmetic:
$f = 1234567890123456789.0;
$s = (string)$f;
echo(serialize($f));
echo "\n";
echo(serialize($s));
d:1.2345678901234568E+18;
s:19:"1.2345678901235E+18";