obtener el numero entero de una division in javascript

To obtain the integer part of a division in JavaScript, you can use the Math.floor() function. This function rounds a number down to the nearest integer.

For example:

index.tsx
let num1 = 7;
let num2 = 3;
let result = Math.floor(num1 / num2); // result will be 2
86 chars
4 lines

In the example above, we first declare two variables num1 and num2 that contain the numbers we want to divide. We then use Math.floor() to obtain the integer part of the division 7 / 3, which is equal to 2.

Note that if you use the / operator to divide two integers in JavaScript, the result will be a floating-point number. To obtain the integer part of the result, you need to use Math.floor() or parse the result as an integer using parseInt() or the bitwise operator ~~.

related categories

gistlibby LogSnag