Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
去除小数点
// ~符号用在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