JS

ROUND OFF NUMBERS IN JAVASCRIPT

THE NUMBER var num = 11.23;   ROUND OFF console.log(Math.round(num)); // 11   CEILING - ALWAYS ROUND UP console.log(Math.ceil(num)); // 12

JAVASCRIPT ROUNDING OFF

01

FLOOR - ALWAYS ROUND DOWN console.log(Math.floor(num)); // 11   TRUNCATE - DROP DECIMALS console.log(Math.trunc(num)); // 11

THE NUMBER var num = 11.237;   MULTIPLIER 2 DECIMAL PLACES = 100 num = num * 100;

ROUND OFF TO DECIMAL PLACE

02

ROUND OFF num = Math.round(num);   REVERT MULTIPLIER num = num / 100;