Created
April 5, 2019 12:09
-
-
Save karl-gustav/66ebe8cf3ce81e7b66c187b08caf1d25 to your computer and use it in GitHub Desktop.
helper math functions in javascript
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
// fixes that 2.55 is rounded to 2.5 and not 2.6 as it should have been | |
export function round(num, digits) { | |
digits = isNaN(digits) ? 2 : digits; | |
return +(Math.round(num + "e+" + digits) + "e-" + digits).toFixed(digits); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment