3 Replies Latest reply on Dec 4, 2009 10:24 AM by Gregory Lafrance

    Trying to add, multiply, and divide variables is a text box

    Marcus Brady Level 1

      I am trying to add, multiply and divide variable is a text box and everything is working except for the last part of the string. If I add or subtract the variables it works fine but If I divide or multiply them it skips them or doesnt even read them. Any Ideas?

       

      text="{dollarFormat.format(Number(inputRate1)* (Number(inputRegularPayWeek1) + Number(inputRegOTWeek1)) + (Number(inputRatePerPoint) * Number(inputPointsWeek1)) +  (Number(inputRate2) * Number(inputDNSSpecialServ1))+ (Number(inputRegularPayWeek1) + Number(inputRegOTWeek1)))}"

       

      it works this way but I need to change that first red + to /.

       

      Thanks for your help

        • 1. Re: Trying to add, multiply, and divide variables is a text box
          Gregory Lafrance Level 6

          Don't use the format() method until the calculation is done.

           

          If this post answers your question or helps, please mark it as such.


          Greg Lafrance
          www.ChikaraDev.com

          Flex Development and Support Services

          • 2. Re: Trying to add, multiply, and divide variables is a text box
            Marcus Brady Level 1

            can you show me how that would look? I get an error if I move it to the end

            • 3. Re: Trying to add, multiply, and divide variables is a text box
              Gregory Lafrance Level 6

              Actually I was wrong on that. You need to check your use of parenthesis for grouping mathematical operations.

               

              This code shows what is actually going on.

               

               

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                creationComplete="init();">
                <mx:Script>
                  <![CDATA[
                    [Bindable] private var inputRate1:Number = .1;
                    [Bindable] private var inputRegularPayWeek1:Number = 2000;
                    [Bindable] private var inputRegOTWeek1:Number = 300;
                    [Bindable] private var inputRatePerPoint:Number = .2;
                    [Bindable] private var inputPointsWeek1:Number = 10; 
                    [Bindable] private var inputRate2:Number = .3;
                    [Bindable] private var inputDNSSpecialServ1:Number = 100; 
                    
                    private function init():void{
                      txt.text += Number(inputRate1) * (Number(inputRegularPayWeek1)+ Number(inputRegOTWeek1)) + "\n";
                      txt.text += (Number(inputRatePerPoint) * Number(inputPointsWeek1)) + "\n";
                      txt.text += (Number(inputRate2) * Number(inputDNSSpecialServ1))/(Number(inputRegularPayWeek1) + Number(inputRegOTWeek1)) + "\n";        
                    }
                  ]]>
                </mx:Script>
                <mx:CurrencyFormatter id="dollarFormat" precision="2" currencySymbol="$"/>
                <mx:Label text="{dollarFormat.format(Number(inputRate1) * (Number(inputRegularPayWeek1)+ Number(inputRegOTWeek1))+
                  (Number(inputRatePerPoint) * Number(inputPointsWeek1))+
                  (Number(inputRate2) * Number(inputDNSSpecialServ1))/(Number(inputRegularPayWeek1) + Number(inputRegOTWeek1)))}"/>
                <mx:TextArea id="txt" width="1000" height="500"/>
              </mx:Application>
              
              
              

               

              If this post answers your question or helps, please mark it as such.


              Greg Lafrance
              www.ChikaraDev.com

              Flex Development and Support Services