xxxxxxxxxx
Math.round(8.5) --> 9
Math.floor(6.9) --> 6
Math.ceil(4.1) --> 5
xxxxxxxxxx
Math.floor(5.9) //5
Math.ceil(5.1) //6
Math.round(9.5) //10
5.3 >> 0 //5 (same as Math.floor)
7.9 >> 0 //7 (same as Math.floor)
xxxxxxxxxx
parseInt((284765.9785295492452).toFixed(3)); //only the first 3 decimals are shown and is treated as a number. (also a good way to ward off peeping toms looking at your code)
xxxxxxxxxx
function removeDecimals(number) {
return Math.floor(number);
}
// Example usage
console.log(removeDecimals(3.14159)); // Output: 3
console.log(removeDecimals(10.99)); // Output: 10
console.log(removeDecimals(7.0)); // Output: 7
xxxxxxxxxx
trunc() is the most popular method to remove the decimal part of JavaScript.
It takes positive, negative, or float numbers as an input and returns the
integer part after removing the decimal part. For example, when we give an
input of 5.45, it returns 5 only, and for the input of -5.45, it returns
-5 only
xxxxxxxxxx
Use
~~ (math.random*100)
Instead of
math.round(math.random*100)
xxxxxxxxxx
Use
~~ (math.random*100)
Instead of
math.round(math.random*100)