Sikau

JavaScript · Day 62 · about 25 min

Numbers and Math

Rounding, random numbers and converting text.

Tidy numbers

Prices with two decimals, a random dice roll, turning "42" typed in a box into the number 42 — JavaScript's built-in Math object and number tools handle these.

Rounding

const price = 123.456;
console.log(Math.round(price));
console.log(Math.floor(price));
console.log(Math.ceil(price));
console.log(price.toFixed(2));
console.log(Math.max(4, 9, 2), Math.min(4, 9, 2));

The rest of this lesson

  • Random numbers and converting textexplain
  • Formatting numbers for peopleexplain
  • Predict the outputpredict
  • Round three wayspredict
  • Your turnwrite code
  • Challengechallenge
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 68 lessons of JavaScript