Home  >  Article  >  Web Front-end  >  How to round in JavaScript

How to round in JavaScript

藏色散人
藏色散人Original
2021-07-05 15:05:243582browse

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

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!

Statement:
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