-3

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

  • 3
    Works for me. `$days = '365'; $TCA = '1614.21'; echo ($TCA / $days);` gives me `4.4224931506849`. As a side note, not sure why you're using strings for numeric values? PHP is great for type juggling, by maybe just use `$days = 365;` and avoid any potential issues with type conversion further down the line?) – Rob Eyre Jul 25 '23 at 10:17
  • It works correctly for me as per output you have mention(0.2261168001685,4.4224931506849).What is issue with this ? – Tejas Prajapati Jul 25 '23 at 10:18

1 Answers1

3

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.

Mohammad Salehi
  • 565
  • 1
  • 12
  • 33