Skip to content

Instantly share code, notes, and snippets.

@sagarpanchal
Created September 30, 2021 07:20
Show Gist options
  • Save sagarpanchal/e83afb27c96ff2df9251ee919d5fa76b to your computer and use it in GitHub Desktop.
Save sagarpanchal/e83afb27c96ff2df9251ee919d5fa76b to your computer and use it in GitHub Desktop.
number.proto.js
Object.defineProperty(Number.prototype, 'decimal', {
get: function decimal() {
Number.precision = 'precision' in Number ? Number.precision : 3;
const f = Math.pow(10, Number.precision);
return Math.round(this * f) / f;
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment