Skip to content

Instantly share code, notes, and snippets.

@remy
Created February 24, 2018 17:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remy/baf4e8d88b840b896db2401e453e0e05 to your computer and use it in GitHub Desktop.
Save remy/baf4e8d88b840b896db2401e453e0e05 to your computer and use it in GitHub Desktop.
Better/more accurate Math.round
const round(value, decimals) =>Number(Math.round(value+'e'+decimals)+'e-'+decimals);
round(1.005, 2); // 1.01
Math.round(1.005, 2); // 1.00
// via http://www.jacklmoore.com/notes/rounding-in-javascript/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment