Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex 无法基于减少的当前值重新计算值_Apache Flex_Actionscript 3_Flexbuilder - Fatal编程技术网

Apache flex 无法基于减少的当前值重新计算值

Apache flex 无法基于减少的当前值重新计算值,apache-flex,actionscript-3,flexbuilder,Apache Flex,Actionscript 3,Flexbuilder,我正试图建立一个最低付款计算器,我有一个问题,最低付款不能计算基于当前的每月价值。我认为应该起作用的…锁定浏览器。我已经注释掉了下面代码中给我带来问题的那一行。如果有人能帮忙,我将不胜感激 <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns

我正试图建立一个最低付款计算器,我有一个问题,最低付款不能计算基于当前的每月价值。我认为应该起作用的…锁定浏览器。我已经注释掉了下面代码中给我带来问题的那一行。如果有人能帮忙,我将不胜感激

<?xml version="1.0" encoding="utf-8"?>
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009" 
xmlns:s="library://ns.adobe.com/flex/spark" 
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="1296" minHeight="768"
width="100%" height="408"  
backgroundColor="#B9ADFF" >

<fx:Declarations>
    <mx:CurrencyFormatter 
    id="Price" precision="2"
    rounding="nearest"
    decimalSeparatorTo="."
    thousandsSeparatorTo=","
    useThousandsSeparator="false"
    useNegativeSign="true"
    currencySymbol="$"
    alignSymbol="left"/>
</fx:Declarations>

<fx:Script>
<![CDATA[

    import mx.collections.ArrayCollection;

    [Bindable]
    private var myDataProvider:ArrayCollection = new ArrayCollection();

    protected function clickHandler(event:MouseEvent):void { 
        myDataProvider.removeAll();

        //Creditor Constants
        var c:Number = Number(1); //start counting at
        var b1:Number = Number(bal1.text); //initial balance
        var r1:Number = Number(apr.text) / 100 / 12;//convert apr to decimal
        var m1:Number = Number(mpp.text) / 100; //convert mpp to decimal

        var mpp:Number = Number(b1 * m1); //minimum payment by percentage
        var ipd:Number = Number(b1 * r1); //interest paid
        var ppd:Number = Number(mpp - ipd); //principle paid

        while(b1 >= 0) {
            myDataProvider.addItem({
                "months" : c, 
                "intBal" : Price.format(b1),  //balance
                "pPaid" : Price.format(ppd),  //principle paid
                "intPd" : Price.format(ipd),  //interest paid
                "minmopmt" : Price.format(mpp) //minimum payment
            });

            c   = (c + 1); //count rows
            b1 -= (ppd);  // Balance minus Principle Paid

            ///////// THE PROBLEM LINE IS BELOW /////////////
                //mpp = (b1 * m1); //minimum payment by percentage

            ipd = (b1 * r1); //Interest Paid
            ppd = (mpp - ipd); // Principle Paid
        }  
    }
]]>
</fx:Script>

<s:Button label="Calculate" x="26" y="238"
          click="clickHandler(event)" />

<s:TextInput x="22" y="277" id="bal1" restrict="[0-9.\-]" textAlign="right" text="1500"/>   
<s:Label x="158" y="287" text="Initial Balance&#xd;"/>      
<s:TextInput x="22" y="307" id="apr" restrict="[0-9.\-]" textAlign="right" text="15"/>
<s:Label x="158" y="317" text="Annual Percentage Rate (APR)"/>      
<s:TextInput x="22" y="337" id="mpp" restrict="[0-9.\-]" textAlign="right" text="2"/>
<s:Label x="158" y="347" text="Minimum Payment Percentage"/>

<mx:DataGrid dataProvider="{myDataProvider}" y="10" id="dg" height="184" x="22">
    <mx:columns>
        <mx:DataGridColumn dataField="months" headerText="Mo" width="30"/>
        <mx:DataGridColumn dataField="intBal" headerText="Balance" width="120"/>
        <mx:DataGridColumn dataField="pPaid" headerText="Principle Paid"  width="120"/>
        <mx:DataGridColumn dataField="intPd" headerText="Interest Paid"  width="120"/>
        <mx:DataGridColumn dataField="minmopmt" headerText="Min Monthly Pmt"  width="120"/>             
    </mx:columns>
</mx:DataGrid>

</s:Application>

= 0) {
myDataProvider.addItem({
“月”:c,
“intBal”:Price.format(b1),//余额
“pPaid”:Price.format(ppd),//支付原则
“intPd”:Price.format(ipd),//支付的利息
“minmopmt”:Price.format(mpp)//最低付款额
});
c=(c+1);//计算行数
b1-=(ppd);//余额减去支付的本金
/////////问题线在下面/////////////
//mpp=(b1*m1);//按百分比计算的最低付款额
ipd=(b1*r1);//已支付利息
ppd=(mpp-ipd);//原则支付
}  
}
]]>

我猜你发现自己陷入了一个无休止的循环。如果上面的计算使ppd为负数(因为你在减去它),或者使它变小得太快以至于你根本无法将b1变为零(也就是说,你有一个平衡的渐近图),就会发生这种情况


解决此问题的一种方法是计算行数,如果行数变大,则中断循环。将“while(b1>=0)”更改为“while(b1>=0&&c<50)”或类似的内容。

必须有一个最低阈值金额才能结束付款。在你的情况下,没有,这正是你所指出的底线。考虑确定最低支付金额。e、 g

var minimumPaymentAmount = 1;

....

if(b1 * m1 < minimumPaymentAmount) 
  mpp =  minimumPaymentAmount;     
else
  mpp =  b1 * m1; 
var minimumPaymentAmount=1;
....
如果(b1*m1<最低支付金额)
mpp=最低支付金额;
其他的
mpp=b1*m1;

你也应该考虑限制计算的行数为500左右,

< P>你发现了芝诺悖论。如果利率(付款)总是与余额成比例,那么余额永远不会完全为零。假设你总是付一半的欠款:

100美元

50美元

25美元

12.50美元

$0.00009536