Skip to content

Instantly share code, notes, and snippets.

@mbreton
Created March 28, 2016 23:05
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 mbreton/8811b39375f9f745a755 to your computer and use it in GitHub Desktop.
Save mbreton/8811b39375f9f745a755 to your computer and use it in GitHub Desktop.
Round a decimal number with the given precision
function roundDecimal(number, precision) {
precision = precision || 2;
const tmp = Math.pow(10, precision);
return Math.trunc(Math.round(number * tmp) / tmp, precision);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment