How to round in JavaScript

藏色散人
Release: 2021-07-05 15:05:24
Original
3489 people have browsed it

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().

How to round in JavaScript

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
Copy after login

Math.ceil() Rounding up

Math.ceil(3.141592654) // 4
Copy after login

Math.round() Rounding

Math.round(3.141592654) // 3
Copy after login

parseInt() Remove the decimal point and the part after the decimal point

parseInt(3.141592654) // 3
Copy after login

~~ Convert data into Number type

~~3.141592654 // 3
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!