It's not floor
that rounds, it's floating point math that does.
This line:
echo 0.99999999999999999;
Prints 1
(demo) because 0.99999999999999999
is too precise to be represented by a (64-bit?) float, so the closest possible value is taken, which happens to be 1
.
0.99999999999999994
is also too precise to be represented exactly, but here the closest representable value happens to be 0.9999999999999999
.
- Is it defined/explained somewhere, at which point it gives "round" value?
It's complicated, but the numbers are rounded almost always.
I believe there is no definition of "from when values will be approximated", but that is a mathematical property that follows from the definitions in the IEEE 754 floating point standard.
To be safe, just assume everything is approximated.
- Is there any function which gives 0 anyhow how many 9 in decimals?
No. The problem is that, for PHP, 0.99999999999999999
is literally the same as 1
.
They're represented by exactly the same sequence of bits, so it can't distinguish them.
There are some solutions to work with bigger precision decimals, but that requires some major code changes.
Probably of interest to you:
Working with large numbers in PHP
Note that while you may get arbitrary precision, you will never get infinite precision, as that would require infinite amounts of storage.
Also note that if you actually were dealing with infinite precision, 0.999...
(going on forever) would be truly (as in, mathematically provable) equal to 1
, as explained in depth in this Wikipedia article.