1Math.round(3.14159 * 100) / 100 // 3.14
2
33.14159.toFixed(2); // 3.14 returns a string
4parseFloat(3.14159.toFixed(2)); // 3.14 returns a number
5
6Math.round(3.14159) // 3
7Math.round(3.5) // 4
8Math.floor(3.8) // 3
9Math.ceil(3.2) // 4
1+3.5 => +3.0
2-3.5 => -4.0
3
4+3.5 => +3.0 using Math.floor()
5-3.5 => -3.0 using Math.ceil()
1//standard round function, except round .5 down instead of up
2function roundHalfDown(num) {
3 return -Math.round(-num);
4}
5roundHalfDown(1.5);// 1
6roundHalfDown(1.6);// 2