JavaScript fast-floor
Use the double NOT bitwise operator to perform a fast-floor.
Math.floor(123.456) // => 123
~~123.456 // => 123
Pro tip: Be careful with negative numbers!
Math.floor(-123.456) // => 124
~~-123.456 // => 123
Written by Florent Cailhol
Related protips
1 Response
Interesting. It does seem faster, to a degree:
http://jsperf.com/math-floor-no-loop & http://jsperf.com/math-floor
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Math
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#