LoginSignup
2
1

More than 3 years have passed since last update.

小数を整数に変換

Last updated at Posted at 2012-12-26
console.log(Math.trunc(12.05)) //12
console.log(Math.trunc(-12.95)) //-12
console.log(Math.trunc(5000000000.1)) //5000000000

以下のようなビット演算子を使う方法は大きい値ではうまくいかない。
@fujitanozomuさんからご指摘頂きました。)

console.log(12.05>>0) //12 OK
console.log(-12.95>>0) //-12 OK
console.log(5000000000.1>>0) //705032704 NG
2
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1