Last active
January 18, 2019 19:41
-
-
Save nicolascine/b2ae04d218035fd6f5133911c1ba028d 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
https://stackoverflow.com/a/35965451 | |
function truncate (num, places) { | |
return Math.trunc(num * Math.pow(10, places)) / Math.pow(10, places); | |
} | |
Then call it with: | |
truncate(3.5636232, 2); // returns 3.56 | |
truncate(5.4332312, 3); // returns 5.433 | |
truncate(25.463214, 4); // returns 25.4632 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment