I am using PHP 5.5 (5.5.28) I have come across a really weird problem with PHP arithmetic
$value=29; $divisor=10;
$mod=$value%$divisor;
echo "$mod<br>";
returns 9 (as expected)
$value=(0.29*100); $divisor=(0.1*100);
$mod=$value%$divisor;
echo "$mod<br>";
returns 8 (????)
I can't find anything about this in the documentation Obviously its relatively easy to write a replacement function and use that However, the problem seems to be bigger, in that I am getting weird rounding errors which mean my ledger entries in the project I am working on are not balancing
Any suggestions?
%expects integers. According to the manual:Operands of modulus are converted to integers (by stripping the decimal part) before processing.. You could of course also usefmod()- that actually returns 9 in your test case - but as @MarkBaker already mentioned, you should never trust the precision of floats when working with ledgers.