PHP accounting is wrong

I am writing a small script to calculate tax values ​​after deductions. My application has several PHP scripts that provide CRUD functionality. I can add monthly expenses, the total amount of invoices, and then calculate how much corporate taxes.

All data is stored in the database, however, when performing the calculations, I encountered an interesting problem, I will simplify the code below so that it can be reproduced:

$total = 1.0;
$tax = 0.2;
$expenses = 0.05;

echo (($total-$tax) + $expenses); // this echo 0.85
// (1.0 - 0.2) + 0.05 

if( (($total-$tax) + $expenses) == 0.85 ) {
    echo "totals add up";
}
else {
    echo "accounting error";
}

The idea is that all totals are calculated as percentages. 1.0 is 100% of the profits, and the costs for the corresponding month are 5% (actually, but for the sake of argument, since my real calculations are a bit confusing), in any case it seems the easiest, I can calculate my calculations.

, 100% () - 20% ( ) + 5% ( ) 85% . .

if, , " ". ?

+5
3

. , .

​​ 100.

+4

You might want to explore the PHP BCMath extension . I found the link by doing a search on this site and posting the question here .

+1
source

All Articles