I'm using JQuery Calculation plugin with the following script:
function recalc() {
jQuery("input[class^=percent]").calc(
"(invoice - cost)/invoice * 100",
{
invoice: jQuery("input[class^=invoice]"),
cost: jQuery("input[class^=cost]")
},
function(s) {
// return the number as a perrcent amount
return s.toFixed(2) + "%";
}
)
};
Just wondering how to stop "NaN%" being displayed when the calculation is invalid (eg. when dividing by zero) and display an empty string instead.
Greatly appreciate any help. Cheers!