Last Updated: February 25, 2016
·
1.003K
· roine

Math.floor quick and easy

To quickly round a float on floor, you can use bitwise operation:
~~1.5 -> 1
~~2.9 -> 2
~~1.1 -> 1
This is a double bitwise NOT, so the processing is also faster.
Here (http://jsperf.com/round-floor-perf) you can test the processing speed

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside