5 Replies Latest reply on Feb 7, 2009 4:54 PM by GumpsterF

    Math Newbie

    GumpsterF
      I feel kinda silly asking this, but I am attempting to build a loan calculator fla, and I have never tried to do math with actionscript 2.0. The tutorials I have read have led me this far, but I keep getting NaN as a result of the trace. What am I doing wrong?
        • 1. Re: Math Newbie
          robdillon Most Valuable Participant
          If InputOne and InputTwo are input textFields then you need to refer to the text that's entered in those textFields using the .text property all the time. So change this line: product = Number(InputOne) + Number(InputTwo);
          to:
          product = Number(InputOne.text) + Number(InputTwo.text);
          if product is a variable. Then in the next line, you should use:
          outputText.text = product;
          if outputText is a dynamic textField and product is a variable.
          • 2. Re: Math Newbie
            GumpsterF Level 1
            Wonderful Rob. Thanks! Works very well. I was able to expand this to multiplication and division and subtraction.
            One more question, in a case of division how would one restrict the answer to two decimal points? I tried a .restrict but it did not work.
            • 3. Re: Math Newbie
              GumpsterF Level 1
              also, could someone tell me how to get the percentage of one number from another?
              [as] percent = Number(input1.text)%Number(input2.text); [/as]
              Did not work...
              • 4. Re: Math Newbie
                GumpsterF Level 1
                I found the answer to the percentage. Never mind :)

                [as] pct = Math.round((input2.text/input1.text)*100); [/as]
                • 5. Re: Math Newbie
                  GumpsterF Level 1
                  I also found my answer to the rounding to 2 decimal places as well.

                  [as] roundedNum = Math.ceil(num*100)/100; [/as]

                  Thanks again to all!