Skip to content

Instantly share code, notes, and snippets.

@avisek
Last active October 7, 2018 18:50
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 avisek/9f9b9e44fbbd83bf403d697e7bea5986 to your computer and use it in GitHub Desktop.
Save avisek/9f9b9e44fbbd83bf403d697e7bea5986 to your computer and use it in GitHub Desktop.
function round(number, places) {
places = Math.max(0, Math.min(places || 0, String(number).split(".")[1].length || 0));
return Math.round(number * Math.pow(10, places)) / Math.pow(10, places);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment