EdwardZZZ / articles

工作点滴记录
2 stars 0 forks source link

小数取整 #36

Open EdwardZZZ opened 6 years ago

EdwardZZZ commented 6 years ago

1.向下取整

parseInt(1.5555) 
0|1.5555
~~1.5555
Math.floor(1.5555)
(1.5555-0.5).toFixed(0)
Math.round(1.5555-0.5)

2.向上取整

Math.ceil(1.5555)
(1.5555+0.5).toFixed(0)
Math.round(1.5555+0.5)

3.四舍五入

1.5555.toFixed(0)
Math.round(1.5555)