How to use Math.floor() for Integer Division In Javascript
In JavaScript, you might sometimes want to perform integer division where you discard the fractional part of the division result. This can be done using the Math.floor() function, which rounds down the result to the nearest integer.
Example: This example describes the integer division of two numbers using the Math.floor() function.
let a = 43;
let b = 10;
// Performing integer division
let result = Math.floor(a / b);
// For printing the result in console
console.log("Integer division result: " + result); // 4
Output
Integer division result: 4
JavaScript Program for Division of Two Numbers
In this article, we will see the basic approaches for the division of two numbers in JavaScript. The division is used in many languages, In JavaScript it can be done using some operators or some other methods.
Javascript has no data type such as integer, float, or double so we can directly use them via letting variables directly.
Example:
Let's take two numbers :
a = 10
b = 5
here , a is dividend and b is divisor
a / b = 10 / 5 = 2
These are the following ways by which we can divide two numbers:
Table of Content
- Using Division / Operator
- Using Functions
- Using Arrow function
- Using Division Assignment Operator
- Using Math.floor() for Integer Division