Skip to content

Instantly share code, notes, and snippets.

@daredrum
Last active April 14, 2017 11:19
Show Gist options
  • Select an option

  • Save daredrum/5299365224a859dcb7bc to your computer and use it in GitHub Desktop.

Select an option

Save daredrum/5299365224a859dcb7bc to your computer and use it in GitHub Desktop.
Rounding techniques
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