Created
February 24, 2018 17:29
-
-
Save remy/baf4e8d88b840b896db2401e453e0e05 to your computer and use it in GitHub Desktop.
Better/more accurate Math.round
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
const round(value, decimals) =>Number(Math.round(value+'e'+decimals)+'e-'+decimals); | |
round(1.005, 2); // 1.01 | |
Math.round(1.005, 2); // 1.00 | |
// via http://www.jacklmoore.com/notes/rounding-in-javascript/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment