A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [F8] reformat integer to money string

  1. #1
    Senior Member
    Join Date
    Mar 2001
    Posts
    197

    [F8] reformat integer to money string

    I'm working in flash 8 and as1.

    I'm using this code that I found on the web..

    Basically I'm just reformatting an integer to a money formatted string. The thing this code doesn’t do is add commas to the number. (Example: 1000 will return $1000.00)

    Does anybody know how I may update this code to include commas in its output?

    Thanks!


    PHP Code:
    function moneyFormat(num){
            
    valor String (Math.round(num 100) / 100);
            
    dot valor.indexOf(".");
            
    money "$";
            if(
    dot == -1){
                    
    valor += ".0";
            }
            
    temp valor.split(".");
            
    addDecimals temp[1].length;
            for(
    i=1i<= addDecimalsi++){
                    
    valor += "0";
            }
            return 
    money+valor;
    }; 

  2. #2
    Senior Member
    Join Date
    Nov 2004
    Location
    Toronto, Canada
    Posts
    194
    split valor into an array, then loop backwards over the resulting array in steps of 3 and use splice to put a comma in. then return array.toString();

    dont forget to start the loop at valor.length - 3 to account for the cents and decimal.

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