minimising digits to 2 of value of variable
A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: minimising digits to 2 of value of variable

  1. #1
    Senior Member
    Join Date
    Feb 2000
    Posts
    226

    Post

    Any body has a suggestion how the Set Variable Action should look like when I would like to change the value of a variable to two digits behind the ‘.’. If this makes sense!?!

    Example: the value of a variable is changed and will probably contain more digits behind the ‘.’ Like 8.8743. When this occurs the variable should be set to the value of 8.87 so I can use it in a textfield for currencies.

    Hope somebody knows how to do this!

  2. #2
    Senior Member
    Join Date
    Mar 2000
    Posts
    235

    Post

    try
    set variable "number" = int(number * 1000)
    set variable "number" = number / 1000

    this will work

    CheerZ
    rosie


    <EMBED src="/cgi-bin/ubb/Members/sigs/00000354.swf" quality=high WIDTH=600 HEIGHT=60 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"> </EMBED>

  3. #3
    Senior Member
    Join Date
    Mar 2000
    Posts
    472

    Cool

    Looking for a currency formatter? I've just recently completed 2 examples of this.
    The first one is in Actionscript, and displays accurately up to 7 integers (and any number of fraction). I've included textfields for every part of the calculation to follow the code action...actual code could be simplified from this experimental edition.

    My second example is a fully functional storefront shopping cart/currency formatter built in Javascript. This is accurate to 14 integers; Item#1 is set up to receive large numbers with fractions, while #2 & #3 are in storefront mode, allowing only whole number input. I'm working on a major addition to this code, to dynamically update the daily world currency exchange rates, and display output based on user preferences. Stay tuned!

    ------------------
    Wright Internet Solutions
    productions@wisolutions.london.on.ca
    DickeeDive: Your Stringed Instruments Connection

    [This message has been edited by Dickee (edited 30 March 2000).]

  4. #4
    Senior Member
    Join Date
    Feb 2000
    Posts
    226

    Post

    Thank you both!

    Your suggestion worked Rosie. However sometimes 3 digits appeared behind the ‘.’ so I changed the 1000 in 100 and this seems to work. Any comments on this!?

    Your right Dickee it is for a currency formatter. I had a look on your site as I forgot about the situation in which only one digit behind the ‘.’appears. I see how you dealt with this. I always wonder how you guys put something like that together.

    However I have to change my whole movie to do deal with it the way you did.

    Can one of you just tell me how the if statement should look like to check if there is only one digit behind the ‘.’ to make the converter complete. Or do I have to change the movie to deal with it the way you, Dickee, did?

  5. #5
    Senior Member
    Join Date
    Mar 2000
    Posts
    235

    Cool

    try this routine

    If (Length (number) = 1)
    Set Variable: "number" = number&".00"
    End If

    CheerZ
    rosie

  6. #6
    Senior Member
    Join Date
    Feb 2000
    Posts
    226

    Post

    This seems not to work properly Rosie. I still get values with only one digit behind the ‘.’
    I had a close look at Dickee’s Converter and came up with this:

    Set Variable: "d100cents" = Substring(input,length(input)-1)
    If (Substring(d100cents,1,1)=".")
    Set Variable: "input" = input&"0"
    End If

    It seems to work but the fact that, although I am quite familiar with all basic actions within Flash, I can only quess about the action it proceeds is driving me mad!!!

    Does anybody of you know where I can find a thorough resource and explanation of the more advanced scripting language(functions) that Flash supports.

  7. #7
    Senior Member
    Join Date
    Mar 2000
    Posts
    472

    Cool

    Actionscript

    Frame 4 says it all ( here it is in plain English):

    Look at the 2nd last character in the rounded number.
    If it's a ".", add "$" leading and "0" following displaynumber.
    If not, add "$" leading displaynumber.
    Loop through entire displaynumber.
    If there is no ".", add ".00" following displaynumber.
    If there is a ".", do nothing to displaynumber.

    Javascript

    You don't need to embed this code into your HTML. A better approach would be to start a folder library called "Javascript" on your server, and create .js function scripts that you can call from Flash using "Get URL". This way, you write the code once, and utilize it as the need arises.

    ....Get URL ("JavaScript src=../Javascript/YourFunction.js")....

    For a crash course in Javascript, with links to NS and IE main Javascript sources, go here .

    So as not to confuse the code, I've made a separate page to include a world currency exchange link, updated at 1:30 MST daily. At present, you must copy and paste your exchange result to input in order to format the number. I still must gather together a currency font set to format all of the final display numbers for all currencies. (and devise the code to set the function!)
    ---------
    International Currency Calculator/Formatter

    ------------------
    Wright Internet Solutions
    productions@wisolutions.london.on.ca
    DickeeDive: Your Stringed Instruments Connection

    [This message has been edited by Dickee (edited 02 April 2000).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com