LoginSignup
0
0

More than 3 years have passed since last update.

JavaScript勉強の記録その18: 数値の操作ができるメソッドまとめ

Posted at

floorメソッド

index.js
let avg = 7.3333;
console.log(Math.floor(avg)); //切り下げ

//=>7

ceilメソッド

index.js
let avg = 7.3333;
console.log(Math.ceil(avg)); //切り上げ

//=>8

roundメソッド

index.js
let avg = 7.3333;
console.log(Math.round(avg)); //四捨五入

//=>7

toFixedメソッド

index.js
let avg = 7.3333;
console.log(avg.toFixed(3)); //少数点第3位まで表示
//=>7.333
console.log(avg.toFixed(2)); //少数点第2位まで表示
//=>7.33

randomメソッド

index.js
let avg = 7.3333;
console.log(Math.random()); //0~1までのランダムの数値を生成

//=>0.49170194909693343
0
0
0

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
0
0