Solved

Flash MX currency view

Posted on 2003-11-03
6
659 Views
Last Modified: 2013-12-13
how do i make the numbers in the dynamic text box appear to have two decimal places eg currency(Flash MX)
thanx
p.s i am calculaitng a cost on one frame and when button pressed the output is shown on the next frame
0
Comment
Question by:noob_x
  • 3
6 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9678130
0
 
LVL 1

Expert Comment

by:Skytzo
ID: 9744844

This one took a while but I think I have it.  I am assuming that you are using actionscript, as this is the only way you can do this.

Here is the Code, with some comments.  I called my dynamic Text Box "number".  I know it is a bit long, but I tried this various ways, and this is the shortest I could come up with.

count is just a number that I used to test on.


count = 123456789.56;

if (count > 1000)
{
               // Get rid of the decimal
      decimal = count%1.0;
      
                // Turn everything but the decimal into a string, as this is what you want to add comma's or periods to
      output = String(count-decimal);
                //Declare a new array
      temp_array = new Array();

                // This is just used as a holder for the string length from base 0              
      number_length = output.length - 1;
      
                // Iterate over string, and add comma's where required, at every third character
      for (i = 0; i < output.length; i++) {
            if (i%3 == 0 && i != 0)
                  temp_array.push(",");
            
            temp_array.push(output.charAt(number_length - i));
      }

               // Pop the items off of the stack and print them to the dynamic string on the screen for the user
      while (temp_array.length)
            number.text += temp_array.pop();

                // Time to add the decimal
      output = String(decimal);

               // Remember to not add the initial 0 in the decimal.  only everything from the decimal point onwards
      for (i = 1; i < output.length; i++)
            number.text += output.charAt(i);
}
else // If the number is smaller than 1000, use as is
      number.text = count;
      
0
 
LVL 1

Accepted Solution

by:
Skytzo earned 125 total points
ID: 9902727
Here is the Verbatim ActionScript Code.  Please make sure that the expert understands actionscript and can run it.
It requires the expert setting up some dynamic and static text fields corresponding to number and temp.


number.text = "";
count = temp.text;

if (count > 1000)
{
     decimal = count%1.0;
     
     output = String(count-decimal);
     temp_array = new Array();

     number_length = output.length - 1;
     
     for (i = 0; i < output.length; i++) {
          if (i%3 == 0 && i != 0)
               temp_array.push(",");
         
          temp_array.push(output.charAt(number_length - i));
     }

     while (temp_array.length)
          number.text += temp_array.pop();

     output = String(decimal);
     for (i = 1; i < output.length; i++)
          number.text += output.charAt(i);
}
else
     number.text = count;
     
0
 
LVL 1

Expert Comment

by:Skytzo
ID: 9902734
A working example can be found for the time being at

http://www.islefx.com
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
python question 5 76
Scripting vs. Programming languages 25 165
Is it possible to programatically fill out a fillable ADOBE PDF form? 9 88
SQL Insert parts by customer 12 34
This is an explanation of a simple data model to help parse a JSON feed
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question