Ads by ProfitSence

Integer Division in JavaScript

Last Updated on Wednesday 5th Oct 2022

JavaScript Integer Division

What is integer division?

What integer division is and how it works. In integer division, the remainder is discarded.

For example,

  • Division of 1 / 2 results in 0.5, integer division of the same expression results in 0.
  • Likewise, 36 / 5 will result in 7 in integer division, but 7.2 in the floating-point division.

Math.floor() function returns the largest integer less than or equal to a given number.

// output: 7

// output: 1


Getting Division Answer in Int

  • Sometimes that value could be in JSON as well, means from a JSON data file.
  • You need to deal with it as if it were a number. But the value that you're getting is a String
  • Need to convert it from the string into a number
  • Global Methods parseInt & parseFloat
					let stringInt = "44";

// output: 44

// output: 25

// output: 99

console.log(parseInt("52 balls in the tray"));
// output: 52