Docs/JavaScript/Numbers & Math

Numbers & Math

Number Methods

  • parseInt() / parseFloat()
  • .toFixed(n) — n desimal
  • Number.isInteger() / Number.isNaN()

Math Object

  • Math.round(), Math.floor(), Math.ceil()
  • Math.max(), Math.min()
  • Math.random() — 0 sampai 1
  • Math.abs(), Math.pow(), Math.sqrt()
  • Math.PI
script.js
Try It →
const o = document.getElementById('output');
o.innerHTML = 
  'parseInt("42px") → '+parseInt("42px")+'
'+
  '(3.14159).toFixed(2) → '+(3.14159).toFixed(2)+'
'+
  'Math.round(4.7) → '+Math.round(4.7)+'
'+
  'Math.floor(4.7) → '+Math.floor(4.7)+'
'+
  'Math.ceil(4.1) → '+Math.ceil(4.1)+'
'+
  'Math.max(1,5,3) → '+Math.max(1,5,3)+'
'+
  'Math.random() → '+Math.random().toFixed(4)+'
'+
  'Random 1-100 → '+Math.floor(Math.random()*100+1)+'
'+
  'Math.sqrt(144) → '+Math.sqrt(144)+'
'+
  'Math.PI → '+Math.PI.toFixed(6);