A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Dynamic Text - Can you display $ and , symbols when manipulating numbers?

  1. #1

    Dynamic Text - Can you display $ and , symbols when manipulating numbers?

    I'd like to display a number like $35,000 in dynamic text, and subsequently subtract from that number. Can you do this?

  2. #2
    Junior Member
    Join Date
    Feb 2009
    Posts
    4
    did you figure it out? i have the same problem

  3. #3
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176

    currency formatting

    first - remove the "$" and "," using the string.split method
    next - do the subtraction
    last - pass the result through a currency formatting function

    in this example the initial amount "$35,000" and the sum
    to be subtracted - 4000 - are hardcoded - str1 & num1

    PHP Code:
    function stripChars(str:String){
    str str.split("$").join("");
    str str.split(",").join("");
    return 
    str;
    }; 

    function 
    currFormat(nValue){
    sResult "";
    var 
    nRound Math.pow(102);
    nValue Math.round(nValue*nRound);
    var 
    sValDec = (2>0) ? "."+String(nValue).substr(String(nValue).length-2) : "";
    var 
    sValInt String(nValue).substr(0String(nValue).length-2);
    sValue String(parseFloat(nValue));
    var 
    sValIntLen sValInt.length;
    nTriple Math.floor((sValIntLen-1)/3);
    nRemainder = ((sValIntLen-1)%3)+1;
    for(var 
    count=0count<nTriplecount++) {
    sResult ","+sValInt.substr((sValIntLen-(3*(count+1))), 3)+sResult;
    }
    if(
    nRemainder){ sResult sValInt.substr(0nRemainder)+sResult; }
    if(
    nPlaces && sValDec.length){
    sResult = (sResult == "") ? "0" sResult;
    sResult += sValDec;
    }
    return 
    "$"+sResult;
    };


    str1 "$35,000";
    num1 4000;

    Result stripChars(str1)-num1;

    output currFormat(Result);
    trace(output); 

  4. #4
    Junior Member
    Join Date
    Feb 2009
    Posts
    4
    great!! thanks!!!!!!!!!!!!!!!!!!!!!!!!

    so, what if i just need the part of:
    "pass the result through a currency formatting function"

    which part of the code will help me?
    This:

    var sValIntLen = sValInt.length;
    nTriple = Math.floor((sValIntLen-1)/3);
    nRemainder = ((sValIntLen-1)%3)+1;
    for(var count=0; count<nTriple; count++) {
    sResult = ","+sValInt.substr((sValIntLen-(3*(count+1))), 3)+sResult;
    }
    if(nRemainder){ sResult = sValInt.substr(0, nRemainder)+sResult; }
    if(nPlaces && sValDec.length){
    sResult = (sResult == "") ? "0" : sResult;
    sResult += sValDec;
    }
    return "$"+sResult;
    };


    ????


    thank you very much i really appreciate it.

  5. #5
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    PHP Code:
    function currFormat(nValue){ 

    // you need all of 
    // the code posted above

    return "$"+sResult;
    }; 

    output currFormat(35000); 
    trace(output); 

  6. #6
    Junior Member
    Join Date
    Feb 2009
    Posts
    4
    thank you!!!!! i will try it

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