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

JavaScript integer division implementation code_javascript skills

WBOY
Release: 2016-05-16 18:15:43
Original
1395 people have browsed it
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;
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template