Methods for rounding in JavaScript: 1. Round down through Math.floor(); 2. Round up through Math.ceil(); 3. Round up through Math.round(); 4. Rounded by parseInt().
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
How to round in JavaScript?
Several methods of rounding in JavaScript
Math.floor() Down Rounding
Math.floor(3.141592654) // 3
Math.ceil() Rounding up
Math.ceil(3.141592654) // 4
Math.round() Rounding
Math.round(3.141592654) // 3
parseInt() Remove the decimal point and the part after the decimal point
parseInt(3.141592654) // 3
~~ Convert data into Number type
~~3.141592654 // 3
Recommended learning: "javascript Advanced Tutorial"
The above is the detailed content of How to round in JavaScript. For more information, please follow other related articles on the PHP Chinese website!