Copying Excel's Circular Reference formula in PHP

馋奶兔 提交于 2019-12-22 11:35:52

问题


I am trying to copy an Excel's Circular Reference formula in PHP.

In Excel I have:

A19 = A25-A22 (result: 8771.65)
A22 = A19*14.1% (result: 1236.80)
A25 = 10000

But, it does not give me correct result when i try to compute it in PHP:

$Tax = 0;
$Gross = 0;    
$Net_Amount = 10000;
$Gross = $Net_Amount - $Tax;
$Tax = $Gross * (14.1/100);

Any idea on how to do this in PHP?


回答1:


By default, Excel will report a warning when you have a circular reference. The exception is if you have told it to handle circular references up to a predefined (you define how many) number of iterations. The way to do the latter in PHP is to use a loop for a predefined number of iterations.

$cycleCount = 12;

$Tax = 0; 
$Gross = 0;     
$Net_Amount = 10000; 
for ($cycle = 0; $cycle < $cycleCount; $cycle++) {
    $Gross = $Net_Amount - $Tax; 
    $Tax = $Gross * (14.1/100); 
}


来源:https://stackoverflow.com/questions/12213537/copying-excels-circular-reference-formula-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!