Bitwise trick for parsing float to int in JavaScript
Bitwise trick for parsing float point to int: use double negation ~~3.33 => 3
Written by Thiago Pontes
Related protips
2 Responses
What language does this work in specifically? I'm not aware of any that it's even valid syntax, let along a "bitwise" way to coerce floats.
Bitwise is implicitly not going to work unless you happen to know how your floats are encoded.
over 1 year ago
·
@richoh My bad, it works just with javascript. I thought I've tested it with other languages but I didn't.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Trick
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#