JavaScript parseInt() Method
A JavaScript predefined function called “parseInt()” accepts values in string format and converts them to integer formats. For instance, it will return “20” if you offer it the floating-point number “20.87” as a parameter. When using parseInt() to divide two integers, the method initially delivers the result in integer format before doing the division operation.
Syntax:
parseInt(a)/parseInt(b);
In this case, the “parseInt()” function divides the values by the division operator after taking values in either integer or decimal format and returning them in integer format.
Example: This example shows the implemetation of the above-explained approach.
Javascript
const a = 411; const b = 2; const r = parseInt(a) / parseInt(b); console.log(r); |
205.5
Division in JavaScript
In every programming language, the operation of division is used often. The division operator (/) is used in JavaScript to divide integers. You may use the division operator or a predefined JavaScript technique that treats every number as an integer to divide two values.
Use the techniques listed below to divide two numbers:
Table of Content
- Division (/) Operator
- JavaScript parseInt() Method
- Using math library in JavaScript
- Using Bitwise Operator