Created
May 4, 2016 21:07
-
-
Save c01nd01r/d806fd4cf4f8c779945c8d26b5136c30 to your computer and use it in GitHub Desktop.
The number of decimal places
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
function decLength(number) { | |
if (number % 1 !== 0) { | |
var str = Number(number).toString(); | |
var pos = str.indexOf('.'); | |
return str.slice(pos+1).length; | |
} | |
return 0; | |
} | |
//decLength(4.98) | |
//2 | |
//decLength(5) | |
//0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment