function formatNumToCurrency(val) {
var minus = '';
if (val.toString().indexOf('-') > -1) {
val = val.toString().replace('-', '');
minus = '-';
}
val = val.toString().replace(/\$|\,/g, '');
val = val.split(".");
val[0] = val[0].split("").reverse().join("");
val[0] = val[0].replace(/(\d{3})/g, "$1,");
val[0] = val[0].split("").reverse().join("");
val[0] = val[0].indexOf(",") == 0 ? val[0].substring(1) : val[0];
val[0] = minus + val[0];
return val.join(".");
}
function formatCurrencyToNum(val) {
return val.replace(/,/g, "");
}
Example
function SetTotalAmount(TotalAmount, Amount, opertaor)
{
if (opertaor == "ADD") {
var Tamount1 = formatCurrencyToNum(TotalAmount);
var Tamount2 = formatCurrencyToNum(Amount);
TotalAmount = parseFloat(Tamount1) + parseFloat(Tamount2);
} else if (opertaor == "SUB") {
}
return formatNumToCurrency(parseFloat(TotalAmount));
}
No comments:
Post a Comment