Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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