Created
October 1, 2018 21:14
-
-
Save hn3000/e784fdf5b0651776975af4a4bc732808 to your computer and use it in GitHub Desktop.
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 roundToDigits(x,n) { | |
let digits = Math.ceil(Math.log(x) / Math.log(10)); | |
let scale = Math.pow(10, n - digits); | |
return Math.round(x * scale)/scale; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment