Created
July 28, 2020 22:47
-
-
Save stevewithington/28e52b77326711ed61ad2a3f2fb0806e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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