Reputation: 327
I have an array that store data. If I subtract two arrays I get an infinately big number. Here is an example
$i[1] = 2.14;
$i[2] = 2.15;
$diff = $i[1] - $i[2];
echo $diff;
The output of this code should be -1
but instead I am getting -0.0099999999999998
? With the code I am making I need the numbers to be exact. Does anyone know why this is happening and how I can fix it?
Thank you
Upvotes: 0
Views: 199
Reputation: 23346
This is because of inaccuracies introduced in floating point operations.
For arbitrary precision operations see BCMath in the manual.
Upvotes: 5