javascript取整函数

来源:互联网 发布:mac os x cdr迅雷下载 编辑:程序博客网 时间:2024/04/19 16:31
1.字符串转化为整形:parseInt(str);如parseInt("7.6")**返回7
2.向上取整,有小数就整数部分加1:Math.ceil(number) ;如Math.ceil(7.6) **返回8
3.向下取整,舍去小数部分 : Math.floor(number) ;如Math.floor(7.6) **返回7
4.四舍五入 :Math.round(number) ;如Math.round(3.4) **返回3, 但是Math.round(3.5)**返回4