문제

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";
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top