Great question! I actually had to deal with this the other day! It might seem like goto just wrote parseInt, but wait! we can be more kind.
Thus, we can use bit operators for several things, and this seems like a great situation! Say I have a number from your question, 12.345, I can use the bit operator '~', which inverts all the bits of your number and converts the number to int in the process! Gotta love JS.
So, now we have an inverted representation of the bits of our number, then if we get '~' again ........ drum roll ......... our number is without decimals! Unfortunately, he does not round.
var a = 12.345;
var b = ~~a;
For this we can use Math.round (). But here you are! You can try it on JSperf to see the small speed you get! Hope this helps!
source
share