Skip to content

Instantly share code, notes, and snippets.

@jhsuZerion
Created May 28, 2018 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhsuZerion/fdf95ae240db1831bea0d1329c370273 to your computer and use it in GitHub Desktop.
Save jhsuZerion/fdf95ae240db1831bea0d1329c370273 to your computer and use it in GitHub Desktop.
/**
* Returns the number of decimals in a numeric value
* @param {string or numeric} n value can be numeric data type or string
* @return {int} number of digits after decimal, false if input is NaN
*/
function numDecimals(n) {
if(typeof n === "undefined" || isNaN(n) === true) return false;
var input_value = String(n);
if(input_value.indexOf(".") === -1) {
return 0;
} else {
return input_value.split(".")[1].length;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment