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 text explain Formatting numbers for people explain Predict the output predict Round three ways predict Your turn write code Challenge challenge Badge quiz quiz What you learned recap Continue this lesson free — run real code in your browser
Continue with GoogleSee all 68 lessons of JavaScript