Skip to content

Instantly share code, notes, and snippets.

@lushijie
Created May 19, 2017 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lushijie/4ecb897c4bc48a75fc84b7d7599c398c to your computer and use it in GitHub Desktop.
Save lushijie/4ecb897c4bc48a75fc84b7d7599c398c to your computer and use it in GitHub Desktop.
去除小数点
// ~符号用在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