JavaScript: Floor a number like a boss
It's not semantic, but it's interesting.
var test = 2.6;
console.log(~~test); // 2
console.log(test | 0); // 2
OBS: It's not safe either. (Thanks @mlb)
~~9999999999.3; // 1410065407
Written by Osvaldo Zonetti
Related protips
5 Responses
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/55789/2a65f435aff57a1efbc51623da2eefbc.jpeg)
this awesome. must be a bug!?! :-)
over 1 year ago
·
For more information: http://michalbe.blogspot.co.uk/2013/03/javascript-less-known-parts-bitwise.html
over 1 year ago
·
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/43518/81829def637962204635704c091036ea.jpg)
Be careful with this, thought :
~~9999999999.3
// 1410065407
over 1 year ago
·
@mlb Well observed.
Thanks for the warning.
over 1 year ago
·
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/39456/c72228efb9afd0798376df9377e7680e.jpeg)
Completely pointless but awesome.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Js
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#