Last active
April 14, 2017 11:19
-
-
Save daredrum/5299365224a859dcb7bc to your computer and use it in GitHub Desktop.
Rounding techniques
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
| n = 10.123456789; | |
| // Bitwise ways | |
| ~~n; // 10 | |
| n|0; // 10 | |
| n^0; // 10 | |
| n>>0 // 10 | |
| // Native | |
| Math.round(n); // 10 | |
| Math.ceil(n); // 11 | |
| Math.floor(n); // 10 | |
| n.toFixed(0); // "10" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment