JS算子|单立杆效应

在JS的整数运算,它相当于去掉小数点,parseInt。当阳性数相当于Math.floor(),负数相当于math.ceil()注。

math.ceil(1)用于圆形。

2。(数学,地板)用作舍入。

三.(数学。圆)在数学中常用于我们的四到五个四舍五入。


console.log(0.6 | 0) / / 0
console.log(1.1 | 0) / / 1
console.log(3.65555 | 0) / / 3
console.log(5 99999 | 0) / / 5
console.log(7.777 | 0) / / 7



注:除三的数学处理数据的方法,我们经常使用parseInt(),parseFloat(),其()和精密()等等。简单的解释:

的固定方法如下:


100.456001.tofixed(2); / / 100.47

100.456001.tofixed(3); / / 100.456

number.prototype.tofixed.call(100.456001,2); / / 100.47




缺点:使用后,它变成了字符串。

对精密的使用如下:


99.456001.toprecision(5); / / 99.456

100.456001.toprecision(5); / / 100.46

number.prototype.toprecision.call(10.456001,5); / / 10.456




单竖杆操作规程

看到上面的例子,可以知道大致垂直杆舍入操作,是只保留正面部分,小数部分被删除,但| 0,怎么操作,为什么| 0可以实现圆的目的单个竖线不等于0

有了这些问题,我们来看看下面的例子:


console.log(3 | 4); / / 7
console.log(4 | 4); / / 4
console.log(8 | 3); / / 11
console.log(5.3 | 4.1); / / 5
console.log(9 | 3455); / / 3455



好吧,让我在这里公布答案。事实上,单立杆|转换为2进制后的余额。例如,我们用简单的例子:

复制代码代码如下:3 | 4

转换为二进制后,011 | 100加111 = 7

复制代码代码如下:4 | 4

转换为二进制后,100 | 100加100 = 4

复制代码代码如下:8 | 3

转换为二进制后,1000 | 011加1011 = 11