Skip to content

Instantly share code, notes, and snippets.

@c01nd01r
Created May 4, 2016 21:07
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 c01nd01r/d806fd4cf4f8c779945c8d26b5136c30 to your computer and use it in GitHub Desktop.
Save c01nd01r/d806fd4cf4f8c779945c8d26b5136c30 to your computer and use it in GitHub Desktop.
The number of decimal places
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