I have this script that calculates numbers input by the user in txtboxPRICE and txtboxTAX and it automatically calculates the TOTAL in txtboxTOTAL. I tested it and it won't calculate pass $1,000? I need it to calculate numbers up to 25 digits.
Code:
function formatCurrency(usFormat) {
usFormat = usFormat.toString().replace(/\$|\,/g, '');
if (isNaN(usFormat))
usFormat = "0";
sign = (usFormat == (usFormat = Math.abs(usFormat)));
usFormat = Math.floor(usFormat * 100 + 0.50000000001);
cents = usFormat % 100;
usFormat = Math.floor(usFormat / 100).toString();
if (cents < 10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((usFormat.length - (1 + i)) / 3); i++)
usFormat = usFormat.substring(0, usFormat.length - (4 * i + 3)) + ',' + usFormat.substring(usFormat.length - (4 * i + 3));
return (((sign) ? '' : '-') + '$' + usFormat + '.' + cents);
}
Code:
function CalTotal() {
var PRICE= document.getElementById("<%=txtboxPRICE.ClientID %>").value;
var TAX = document.getElementById("<%=txtboxTAX.ClientID %>").value;
if (PRICE!= "" || TAX != "") {
if (TAX .substring(1) > PRICE.substring(1)) {
document.getElementById("<%=txtboxTOTAL.ClientID %>").value = PRICE.substring(1) - TAX .substring(1);
}
else {
document.getElementById("<%=txtboxTOTAL.ClientID %>").value = PRICE.substring(1) - TAX .substring(1);
}
}
}