I have a table that displays an arithmetic operation with values from database. In database all values are FLOAT type. My arithmetic operation is:
$difference = $row['variable1']+$row['variable2']-$row['variable3']-$row['variable4'];
<td><?php echo (round($difference, 2)) ?></td>
So. my problem is the the calculation of some values that i insert. For example:
variable1=10
variable2=10.08
variable3=10
variable4=10.08
Normal it must give difference=0; but it is displaying difference= -0; In every case if i use values with xx.07, xx.08, xx.09 it gives me an result = -0; It doesn't happen wih values up to xx.07.
Example:
variable1=10; variable2=10.06; variable3=10;variable4=10.06; The result = 0;
If i don't round the difference it gives a result like this : -5.68434188608E-14;
I tried to round variables before calculation, i tried to use "()"
in the calculation, i tried to round variables directly in operation, because i thinked it takes more than 2 values after <
,>
(FLOAT type).
I tried to round values when inserting in database, but it gives me error inserting for input fields, because it have more than 4 variables(not used in the difference operation).
Thx for help me in this problem, i really don't understand why it happens like this.