PHP Division isn't calculating property, help please

35 Views Asked by At

I have one variable ($TotalCountyTaxAmount) I want to divide by 365 to calculate a daily tax rate. In this example the variable value is 1614.21. When I divide the variable by the number of days (e.g. $TCA / $days), I get 0.2261 which is incorrect. The correct answer should be 4.42. When I change the order (e.g. $days / $TCA) I get a result of 365.


//calculate daily tax rate
$days = '365';
$TCA = str_replace("$", "", $TotalCountyTaxAmount); //strip dollar sign 
echo ($days / $TCA);  
echo ($TCA / $days);  

TIA

I have tried using the number_format() which didn't work. I am limited to the functions available here

1

There are 1 best solutions below

0
Mohammad Salehi On

I guess the output is correct and you confuse between that two operation (check this).

0.2261 or more precise 0.2261168001685 is the result of $days / $TCA, and the result of $TCA / $days / $days is 4.4224931506849.

also you can use number_format to format the numeric output.