Created
May 28, 2018 11:47
-
-
Save jhsuZerion/fdf95ae240db1831bea0d1329c370273 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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