Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Created July 28, 2020 22:47
Show Gist options
  • Save stevewithington/28e52b77326711ed61ad2a3f2fb0806e to your computer and use it in GitHub Desktop.
Save stevewithington/28e52b77326711ed61ad2a3f2fb0806e to your computer and use it in GitHub Desktop.
let x = 30.039853244;
Number(Math.round(x + 'e2') + 'e-2); // 30.04
const round = (num, digits) => {
return Number(Math.round(num + 'e' + digits) + 'e-' + digits);
}
let y = 3.141592653589793238;
round(y, 3); // 3.142
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment