Home > Article > Web Front-end > How to convert float to int type in javascript
Conversion method: 1. Use the "parseInt(float value)" statement; 2. Use the "Math.ceil(float value)" statement; 3. Use the "Math.round(float value)" statement; 4 , use the "Math.floor(float value)" statement.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
javascript Force conversion of float to int type
1. Discard the decimal part and keep the integer part
parseInt(7/2)
2. Round up. If there is a decimal, add 1 to the integer part
Math.ceil(7/2)
3. Round off
Math.round(7/2)
4 , Round down
Math.floor(7/2)
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How to convert float to int type in javascript. For more information, please follow other related articles on the PHP Chinese website!