A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [F8] Stuck on if/else statement, making decimals for money

  1. #1
    Member
    Join Date
    Mar 2006
    Posts
    43

    [F8] Stuck on if/else statement, making decimals for money

    I have a money counter on my site. Each coin will be with a certain amount, link .25.

    But whenthe counter gets to $1.50 or $0.50, it displays $1.5 or $0.5, leaving the last zero off. It looks better if it shows $1.50 or $0.50. Same thing when it gets to a whole number, instead of showing $2.00 it shows $2

    So I tried to set up an if/else statement. It is below:
    Code:
    SomeNumber="1" || "2" || "3" || "4" || "5" || "6" || "7" || "8" || "9" || "0"
    
    if (amount==SomeNumber+"."+SomeNumber+SomeNumber){
    	donothing
    } else if (amount==SomeNumber+"."+SomeNumber){
    	amount=amount+"0"
    } else if (amount==SomeNumber){
    	amount=amount+".00"
    }
    I tried switching it around many different ways. I even tried this:

    Code:
    if (amount=="1" || "2" || "3" || "4" || "5" || "6" || "7" || "8" || "9" || "0"+"."+"1" || "2" || "3" || "4" || "5" || "6" || "7" || "8" || "9" || "0"+"1" || "2" || "3" || "4" || "5" || "6" || "7" || "8" || "9" || "0"){
    	donothing
    } else if (amount=="1" || "2" || "3" || "4" || "5" || "6" || "7" || "8" || "9" || "0"+"."+"1" || "2" || "3" || "4" || "5" || "6" || "7" || "8" || "9" || "0"){
    	amount=amount+"0"
    } else if (amount=="1" || "2" || "3" || "4" || "5" || "6" || "7" || "8" || "9" || "0"){
    	amount=amount+".00"
    }
    With that, what it is doing is reading the first line and just stopping before the "." because the amount will equal one of the numbers. So I tried putting another set of quotes around the first set of numbers, then the second set, ect. But that didn't work either.

    Is there a different punctuation mark to use in somthing like that?


    If anyone knows an easier way to do this, please let me know!

  2. #2
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,930
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  3. #3
    Member
    Join Date
    Mar 2006
    Posts
    43
    Would work great if the numers went past 2 decimals, but since sometimes I'm dealing with whole numbers or numbers to the tenths place, Flash automaticly takes off the extra zero(s). I want to keep the zeros.

  4. #4
    Member
    Join Date
    Mar 2006
    Posts
    43
    I found out how to do it now. If anyone else needs to know how to do this, this is the code:

    Code:
    number=amount
    rounder = int((number)*100)/100;
    if (rounder == int(rounder))
    {
      rounder += '.00';
    }
    else if (rounder*10 == int(rounder*10))
    {
      rounder += '0';
    }
    amount=rounder
    I searched the board. I normally just search the tutorials and movies section of the main site and once I don't find it there I post my problem here. Next time, I'll search the board if I have another problem before posting.

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