分享

js只保留整数,向上取整,四舍五入,向下取整等函数

 Estellxu 2016-12-15
 1.丢弃小数部分,保留整数部分
  eg:parseInt(5/2)
2.向上取整,有小数就整数部分加1
 eg:Math.ceil(5/2)
3.四舍五入.
 eg:Math.round(5/2)
4.向下取整
 eg:Math.floor(5/2)
举例:
aa=parseInt(5/2)
alert("取整"+aa);
//2(丢掉小数部分)
bb=Math.ceil(5/2)
alert("ceil"+bb);
//3(向上取整)
cc=Math.round(5/2);
alert("round"+cc);
//3(四舍五入)
dd=Math.floor(5/2);
alert("floor"+dd);
//2(向下取整)


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多