function divide(a, b) { var result = (a / b * 100).toFixed(2); if (isNaN(result)) { result = 0; } return result; }