Skip to content

Instantly share code, notes, and snippets.

@sksar
Created April 3, 2022 06:51
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 sksar/122c9d50da516adabaf53ff91df9c79b to your computer and use it in GitHub Desktop.
Save sksar/122c9d50da516adabaf53ff91df9c79b to your computer and use it in GitHub Desktop.
Precision Rounding
function ROUND(x, p) {
const a = Math.floor(x * 10 ** p) * 10;
const c = Math.floor(x * 10 ** (p + 1)) - a;
return (c >= 5 ? a + 10 : a) / 10 ** (p + 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment