Possible Duplicate:
What is the “double tilde” (~~) operator in JavaScript?
My Code:
<SCRIPT type="text/javascript">
var num = 2.52;
alert(~~num);
</SCRIPT>
It is giving the result as 2
. Why it is leaving the decimals? Any Ideas.
Possible Duplicate:
What is the “double tilde” (~~) operator in JavaScript?
My Code:
<SCRIPT type="text/javascript">
var num = 2.52;
alert(~~num);
</SCRIPT>
It is giving the result as 2
. Why it is leaving the decimals? Any Ideas.
Here is an explanation http://james.padolsey.com/javascript/double-bitwise-not/
The bitwise NOT operator (~) will take its operand, convert it to a 32-bit integer, and will invert each bit so that each 0 becomes a 1 and vice versa.
Every bitwise operation in JavaScript does convert its arguments to signed 32bit intergers. This will strip of your decimals. Else, you might expect the double bitwise NOT to yield its argument unchanged.
Simply remove the tildes (~).
<SCRIPT type="text/javascript">
var num = 2.52;
alert(num);
</SCRIPT>