Skip to content

Instantly share code, notes, and snippets.

@ESeufert
Created May 2, 2014 09:19
Show Gist options
  • Save ESeufert/9971c705138392d11a2c to your computer and use it in GitHub Desktop.
Save ESeufert/9971c705138392d11a2c to your computer and use it in GitHub Desktop.
function safeDivide(num1, num2) {
if (isNaN(parseFloat(num2)) || isNaN(parseFloat(num1)) || num2 == 0) {
return 0;
}
return Math.round( parseFloat(num1) / parseFloat(num2) * 100 ) / 100;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment