Skip to content

Instantly share code, notes, and snippets.

@psiborg
Created January 6, 2012 08:31
Show Gist options
  • Select an option

  • Save psiborg/1569704 to your computer and use it in GitHub Desktop.

Select an option

Save psiborg/1569704 to your computer and use it in GitHub Desktop.
JS Prototype - roundTo
if (!Number.prototype.roundTo) {
Number.prototype.roundTo = function (precision) {
var power = Math.pow(10, precision || 0);
return String(Math.round(this * power) / power);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment