A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: display score as dollar and cents amounts

  1. #1
    Member
    Join Date
    Dec 2004
    Posts
    68

    display score as dollar and cents amounts

    I’m making a game that requires the user to earn money.
    I’m able to display the numbers using:

    scoreDisplay.text = gameScore.toFixed(2);

    But I cannot seem to create a variable that will add 50 cents or 75 cents to the total and have it display properly.

    Does anyone have a solution?

  2. #2
    Senior Member dudeqwerty's Avatar
    Join Date
    Mar 2005
    Location
    Bosnia
    Posts
    1,626
    Anything after the decimal point will the the number of cents.

    So if you have 6.45, thats 6 dollars and 45 cents.

    To get the .45 you subtract the integer part from the floating point number.

    so:
    Code:
    var gameScore:Number = 6.45;
    var dollars:Number = int(6.45);
    var cents:Number = gameScore - dollars;
    New sig soon

  3. #3
    When you know are. Son of Bryce's Avatar
    Join Date
    Aug 2002
    Location
    Los Angeles
    Posts
    838
    Just to clarify the code a bit. By using int() to cast the Number as an Integer it chops off the decimals. Integers must be a whole number, while Numbers can be anything.

    I only know this cause I read an AS3 book so I figured it may confuse some people.

  4. #4
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,378
    Quote Originally Posted by dudeqwerty View Post
    Anything after the decimal point will the the number of cents.

    So if you have 6.45, thats 6 dollars and 45 cents.

    To get the .45 you subtract the integer part from the floating point number.

    so:
    Code:
    var gameScore:Number = 6.45;
    var dollars:Number = int(gameScore); // NOT 6.45
    var cents:Number = gameScore - dollars;
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  5. #5
    Senior Member dudeqwerty's Avatar
    Join Date
    Mar 2005
    Location
    Bosnia
    Posts
    1,626
    Yeah, nice one ImprisonedPride.
    New sig soon

  6. #6
    Member
    Join Date
    Dec 2004
    Posts
    68
    Thanks! I was able to make it work.

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