Created
May 19, 2017 04:00
-
-
Save lushijie/4ecb897c4bc48a75fc84b7d7599c398c to your computer and use it in GitHub Desktop.
去除小数点
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ~符号用在JavaScript中有按位取反的作用,~~即是取反两次,而位运算的操作值要求是整数,其结果也是整数,所以经过位运算的都会自动变成整数,可以巧妙的去掉小数部分,类似于parseInt,比如: | |
let a = 1.23; | |
let b = -1.23; | |
console.log(~~a); // 1 | |
console.log(~~b); // -1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment