JS的除法应用 求余,取整,进一法,四舍五入

JS的除法运算:

/ 除法运算

% 求余运算

列如:

    const a=256;

    const b=a/100;  // b=2.56

    const c=a%100;// c=56

1.取整:parseInt():只保留整数位:在这里等同Math.floor()

    const d=parseInt(b); //d=2

2.进一法: Math.ceil():向上取整,有小数就整数部分加1

const a=125;

const b=155;

const c=Math.ceil(a/100); // c=2

const d=Math.ceil(d/100);//d=2

3.向下取整:Math.floor()

const a=125;

const b=155;

const c=Math.floor(a/100); // c=1

const d=Math.floor(d/100);//d=1

4.四舍五入:Math.round()

const a=125;

const b=155;

const c=Math.floor(a/100); // c=1

const d=Math.floor(d/100);//d=2

-------------------------------------------------------------------------------------------------------------------------------------------------------------------如遇到问题:+WX:WAZJ-0508,及时联系---------------------------------------------------------------------------------------------------------------------------------------------------

发布了58 篇原创文章 · 获赞 41 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/Zeng__Yi/article/details/84619101