I'd like to display a number like $35,000 in dynamic text, and subsequently subtract from that number. Can you do this?
I'd like to display a number like $35,000 in dynamic text, and subsequently subtract from that number. Can you do this?
did you figure it out? i have the same problem :crazy:
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(10, 2);
nValue = Math.round(nValue*nRound);
var sValDec = (2>0) ? "."+String(nValue).substr(String(nValue).length-2) : "";
var sValInt = String(nValue).substr(0, String(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=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;
};
str1 = "$35,000";
num1 = 4000;
Result = stripChars(str1)-num1;
output = currFormat(Result);
trace(output);
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. :):lovers:
PHP Code:function currFormat(nValue){
// you need all of
// the code posted above
return "$"+sResult;
};
output = currFormat(35000);
trace(output);
thank you!!!!! i will try it :) :) :) :angel: