Removal method: 1. Use parseInt(), the syntax "parseInt(value)"; 2. Use ceil(), the syntax "Math.ceil(value)"; 3. Use floor(), the syntax " Math.floor(value)"; 4. Use round(), the syntax is "Math.round(value)".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
Javascript method to remove decimal part
1. Use parseInt() function to round
// 丢弃小数部分,保留整数部分 parseInt(3.141592654) // 3
2. Use the ceil() function to round up
// 向上取整,有小数就整数部分加1 Math.ceil(3.141592654) // 4
3. Use the floor() function to round down
// 向下取整,丢弃小数部分 Math.floor(3.141592654) // 3
4. Use the round() function to round
// 四舍五入 Math.round(3.141592654) // 3
[Related recommendations: javascript learning tutorial]
The above is the detailed content of How to remove decimal part in javascript. For more information, please follow other related articles on the PHP Chinese website!