Home >Web Front-end >JS Tutorial >JavaScript integer division implementation code_javascript skills

JavaScript integer division implementation code_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:15:431396browse
Copy code The code is as follows:

//Integer division
function Div(exp1, exp2)
{
var n1 = Math.round(exp1); // Rounding
var n2 = Math.round(exp2); // Rounding
var rslt = n1 / n2; // Divide
if (rslt >= 0)
{
rslt = Math.floor(rslt); //The return value is the maximum integer value less than or equal to its numeric parameter.
}
else
{
rslt = Math.ceil(rslt); //The return value is the smallest integer greater than or equal to its numeric parameter.
}
return rslt;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn