JavaScript – Perform Integer Division and Get Remainder integer-divisionjavascriptmathmodulo In JavaScript, how do I get: The whole number of times a given integer goes into another? The remainder? Best Answer 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 Related SolutionsJavaScript Math – Getting Place Values of a Number Using Modulus var ones = Math.floor(num % 10), tens = Math.floor(num/10 % 10), hundreds = Math.floor(num/100 % 10), thousands = Math.floor(num/1000 % 10), tenThousands = Math.floor(num / 10000 % 10), hundredThousands = Math.floor(num / 100000 % 10), millions = Math.floor(num / 1000000 % 10), tenMillions = Math.floor(num / 10000000 % 10), hundredMillions = Math.floor(num / 100000000 % 10); Managed to get to 100 million. JavaScript – Division and Remainder of Large Numbers thank you John Coleman javascript version : function calculateMod(str, mod) { var n = str.length; if (n <= 10) { return parseInt(str) % mod; } else { var first = str.substring(0, n - 10) var second = str.substring(n - 10) return (calculateMod(first, mod) * (Math.pow(10, 10) % mod) + parseInt(second) % mod) % mod; } } Related Question
Best Answer
For some number
y
and some divisorx
compute the quotient (quotient
)[1] and remainder (remainder
) as:Example:
[1] The integer number resulting from the division of one number by another