Skip to content

Instantly share code, notes, and snippets.

@hperantunes
Created January 28, 2020 17:46
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 hperantunes/0fd92de6e02ef80550de28f2d37d0543 to your computer and use it in GitHub Desktop.
Save hperantunes/0fd92de6e02ef80550de28f2d37d0543 to your computer and use it in GitHub Desktop.
function decimalPlaces(value) {
const match = ("" + value).match(/(?:[,.](\d+))?(?:[eE]([+-]?\d+))?$/);
if (!match) {
return 0;
}
return Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment