Created
April 3, 2022 06:51
-
-
Save sksar/122c9d50da516adabaf53ff91df9c79b to your computer and use it in GitHub Desktop.
Precision Rounding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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