That floating point numbers in PHP are inaccurate is well known (http://php.net/manual/de/language.types.float.php), however I am a bit unsatisfied after the following experiment:
var_dump((2.30 * 100)); // float(230)
var_dump(round(2.30 * 100)); // float(230)
var_dump(ceil(2.30 * 100)); // float(230)
var_dump(intval(2.30 * 100)); // int(229)
var_dump((int)(2.30 * 100)); // int(229)
var_dump(floor(2.30 * 100)); // float(229)
The internal representation must be something like 229.999998
.
var_dump((2.30 * -100)); // float(-230)
var_dump(round(2.30 * -100)); // float(-230)
var_dump(ceil(2.30 * -100)); // float(-229)
var_dump(intval(2.30 * -100)); // int(-229)
var_dump((int)(2.30 * -100)); // int(-229)
var_dump(floor(2.30 * -100)); // float(-230)
The internal representation must be something like -229.999998
.
Ok as far as I understand - integer casting as well as the intval function simply cut of everything behind the point. Good to know.
However var_dump()
gives me a value of 230 though the real value must be different according to those results.
Now have a look at this:
$a = 230.0;
var_dump($a); // float(230)
var_dump((int) $a); // int(230)
That means the internal representation of the floating point number must be different here. If I want to know the exact value of a float therefore I can not debug using var_dump
as I am used to right? How can I debug an exact float value?