var floatingPointPart = (18/7) % 1;
var integerPart = Math.floor(18/7);
Answer from Zéychin on Stack Overflow Top answer 1 of 9
56
var floatingPointPart = (18/7) % 1;
var integerPart = Math.floor(18/7);
2 of 9
23
Math.floor has the problem of rounding of the result to wrong direction in case of negative number it would be better to use bitwise operation to obtain interger quotients.
var quot = ~~(num/num1)
Hopefully this works for you!
W3Schools
w3schools.com › js › js_arithmetic.asp
JavaScript Arithmetic
In arithmetic, the division of two integers produces a quotient and a remainder.
Videos
Divide One Decimal by Another with JavaScript - Free Code ...
00:38
JavaScript Basic 19: Divide Two Decimals | FreeCodeCamp | - YouTube
07:46
Javascript program to Find Quotient and Remainder - GeeksforGeeks ...
00:53
Divide One Number by Another with JavaScript - freeCodeCamp - Basic ...
04:05
Learn Javascript: Working with Numbers - Quotient and Remainder ...
GeeksforGeeks
geeksforgeeks.org › javascript › find-quotient-and-remainder-by-dividing-an-integer-in-javascript
Find quotient and remainder by dividing an integer in JavaScript - GeeksforGeeks
let a = 39; let b = 5; function Geeks() { console.log("quotient = " + Math.floor(a / b)) console.log("remainder = " + a % b); } Geeks()
Published September 6, 2025
TutorialsPoint
tutorialspoint.com › find-quotient-and-remainder-by-dividing-an-integer-in-javascript
Find quotient and remainder by dividing an integer in JavaScript
The quotient is the result of the division, and the remainder is the part of the number that is left over after the division.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Division
Division (/) - JavaScript | MDN
The division (/) operator produces the quotient of its operands where the left operand is the dividend and the right operand is the divisor.
YouTube
youtube.com › watch
Calculate Quotient in JavaScript | Integer Division in JavaScript | Math.floor trunc - YouTube
The best method for calculating quotient in javascript,Math.floor()Math.trunc()Bitwise Not
Published July 31, 2022
Wikitechy
wikitechy.com › tutorials › javascript › how-to-perform-integer-division-and-get-the-remainder-we-javascript
javascript tutorial - How to perform integer division and get the remainder we javascript ? - By Microsoft Award MVP - Learn in 30sec javascript - java script | wikitechy
In JavaScript, how do we get: the whole number of times a given integer goes into another? the remainder? For some number y and some divisor x compute the quotient (quotient) and remainder (remainder) as: var quotient = Math.floor(y/x); var remainder = y % x; Copy Code ·
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Remainder
Remainder (%) - JavaScript | MDN
The remainder (%) operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend.
TutorialsPoint
tutorialspoint.com › How-to-perform-integer-division-and-get-the-remainder-in-JavaScript
How to perform integer division and get the remainder in JavaScript?
In this tutorial, we will learn how to perform integer division and get the remainder in JavaScript. The division operator (/) returns the quotient of its operands, where the dividend is on the left, and the divisor is on the right. When another splits one operand, the remainder operator (%) ...
Decodingweb
decodingweb.dev › js-integer-division
Integer division in JavaScript explained
September 22, 2023 - In this guide, you’ll learn how to do integer division in JavaScript. The division operator in JavaScript (/) divides two numbers (dividend and divisor) and returns the quotient as a floating point number (rather than the quotient and the remainder of a division separately).
GoLinuxCloud
golinuxcloud.com › home › javascript › javascript integer division (divide without remainder explained)
JavaScript Integer Division (Divide Without Remainder Explained) | GoLinuxCloud
October 17, 2022 - Since JavaScript always returns a floating-point value when using the / operator, we must use additional methods to remove the decimal portion. The Math.floor() method rounds a number down to the nearest integer. By combining it with the division operator, we can achieve integer division. ... If you also want the remainder, you can use the modulus operator %. ... const y = 34; const x = 12; const quotient = Math.floor(y / x); const remainder = y % x; console.log(`quotient - ${quotient}, remainder - ${remainder}`);
Stack Abuse
stackabuse.com › bytes › integer-division-and-finding-the-remainder-in-javascript
Integer Division and Finding the Remainder in JavaScript
September 6, 2023 - However, we can achieve this by first performing a regular division using the / operator, and then using the Math.floor() function to round down to the nearest integer. let num1 = 10; let num2 = 3; let quotient = Math.floor(num1 / num2); console.log(quotient); // Output: 3
Top answer 1 of 16
1905
For some number y and some divisor x compute the quotient (quotient)[1] and remainder (remainder) as:
const quotient = Math.floor(y/x);
const remainder = y % x;
Example:
const quotient = Math.floor(13/3); // => 4 => the times 3 fits into 13
const remainder = 13 % 3; // => 1
[1] The integer number resulting from the division of one number by another
2 of 16
519
I'm no expert in bitwise operators, but here's another way to get the whole number:
var num = ~~(a / b);
This will work properly for negative numbers as well, while Math.floor() will round in the wrong direction.
This seems correct as well:
var num = (a / b) >> 0;
Note: Only use ~~ as a substitution for Math.trunc() when you are confident that the range of input falls within the range of 32-bit integers.
GeeksforGeeks
geeksforgeeks.org › division-in-javascript
Division in JavaScript | GeeksforGeeks
April 28, 2025 - Two operands may be divided; the divided operand is known as the "dividend," while the dividing operand is referred to as the "divisor." The "quotient" is the value that remains after division.