当前位置:网站首页>js取整的小技巧
js取整的小技巧
2022-06-28 08:06:00 【庸懒】
js取整
其实是一个很小的知识点但感觉很有用的所以在这里记录一下。我们一般js取整都是使用的parseInt来取整,例如下面的情况:
但是其实还可以使用下面的方法
这种运算符是按位非运算符,这是一个二进制运算符,他的原理我简单表述一下。按位非的运算规则是首先将数字转换成二进制,然后按位取反。第一位是符号位,如果为1则表示负数,除了第一位的符号位其余都再次取反然后+1,如果想更细致的了解js位运算符可以参考这里的W3C。
因为是在以二进制的形式操作数字所以效率会更高而且看起来也更有逼格,所以这么好的东西为啥不用呢*^*。
边栏推荐
猜你喜欢

Redis cluster deployment and application scenarios

你了解TCP協議嗎(二)?

B_QuRT_User_Guide(28)

asp. Net datalist when there are multiple data displays
![[shangpinhui] project notes](/img/aa/043dd16c20348f1f80ca5e9e4ad330.png)
[shangpinhui] project notes

Section Xi. Axi of zynq_ Use of DMA

NLP sequence can completely simulate human brain intelligence

Ambari (V) ---ambari integrated Azkaban (valid for personal test)

Introduction to Devops Basics

Do you know TCP protocol (2)?
随机推荐
2022巴黎时装周儿童单元6.19武汉站圆满落幕
Three step problem of leetcode
Doris学习笔记之介绍、编译安装与部署
Es data export CSV file
MySQL single table access method
Kubernetes theoretical basis
asp. Net error "/" server error in the application. String or binary data would be truncated. The statement...
Jenkins' common build trigger and hook services (V)
Eslint syntax monitoring off
Introduction to kubernetes (I)
【尚品汇】项目笔记
城联优品向英德捐赠抗洪救灾爱心物资
Section 8: DMA of zynq
【学习笔记】最短路 +生成树
十大券商注册开户靠谱吗?安全吗?
MySQL tablespace parsing
Is it reliable for the top ten securities companies to register and open accounts? Is it safe?
协程、asyncio、异步编程
Study notes 22/1/11
ROS 笔记(08)— 服务数据的定义与使用