js 各种取整方式及方法

来源:互联网 发布:不收会费的淘宝兼职 编辑:程序博客网 时间:2024/06/03 16:36
1.直接丢弃小数部分,保留整数部分 

a:parseInt(1.5555) 

b: 0|1.5555


2.向上取整

a: Math.ceil(1.5555)

b: (1.5555+0.5).toFixed(0)

c: Math.round(1.5555+0.5)


3.向下取整 

a: Math.floor(1.5555)

b: (1.5555-0.5).toFixed(0)

c:Math.round(1.5555-0.5)


4.四舍五入. 

b:1.5555.toFixed(0)

c:Math.round(1.5555)

原创粉丝点击