I'm struggling to make accounting software in PHP. And i got some bug from float precision.
Here is the sample unworking code :
$a = (float) 2258574.18;
$b = (float) 2058555.18;
$c = 200019;
$d = 0;
($b+$c-$d == $a ) ? $x = "equals" : $x = "!equals";
echo $x;
Outputs :
!equals
I was using round()
abs()
but doesnt solved.
It work if i only convert it to int (int)
.
I almost suicide because of this.