开发者

Bitwise conversion of decimal to integer

开发者 https://www.devze.com 2023-02-03 12:08 出处:网络
I don\'t know if this is specif开发者_运维百科ic to JavaScript. var pi = 3.14159265 alert(pi|0) This will output 3.

I don't know if this is specif开发者_运维百科ic to JavaScript.

var pi = 3.14159265
alert(pi|0)

This will output 3.

Can someone explain what happens to the decimal fractions part during the bitwise OR operation?


The bitwise or operator only operates on integer types, so the fractional component is silently stripped off the number. A bitwise or with zero will always result in the other operand. Therefore, you get 3.


Bitwise operator only works on integers.

pi (3.14..) is converted to an INT which truncates the decimal places to 3.

0

精彩评论

暂无评论...
验证码 换一张
取 消