Es6-str-math-trunc

提供:Dev Guides
移動先:案内検索

ES6-Math.trunc()

この関数は、小数桁を削除して、数値の整数部分を返します。

構文

下記の構文は、* Math.trunc()関数の構文です。ここで、 *X -は数値を表します。

Math.trunc( x ) ;

<script>
   console.log(Math.trunc(-3.5))//-3
   console.log(Math.trunc(-3.6))//-3
   console.log(Math.trunc(3.5))//3
   console.log(Math.trunc(3.6))//3
</script>

上記のコードの出力は以下のようになります-

-3
-3
3
3