Use JavaScript's floor() Method to do Integral Division

Although JavaScript does not have a mathematical operator that results in the integer part of a division operation (called integral division, or Div in some languages), you can use the Math object's floor() method to create that result, as long as the values you are working with are positive.

The Math object's floor() method returns the next integer less than or equal to the value it is passed. For example:

var result = Math.floor(5/3) //result = 1

The result is the equivalent of having the decimal part (or remainder) removed after the division operation has taken place, which is exactly what an integral division operation would do.

Source: Myra Pelz
Viewed 4936 times