What are the methods of javascript division and rounding?

藏色散人
Release: 2021-11-11 16:15:09
Original
27074 people have browsed it

Javascript division and rounding methods include: 1. Rounding is achieved through the round method; 2. Rounding up is achieved through the ceil method; 3. Rounding down is achieved through the floor method; 4. Forced through parseInt Rounding.

What are the methods of javascript division and rounding?

The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.

What are the methods of javascript division and rounding?

Four methods of javascript division results rounding

Math.round(7/2)=4 //四舍五入,round() 方法可把一个数字舍入为最接近的整数。 Math.ceil(7/2)=4 //强制向上取整,ceil() 方法将数字向上舍入为最接近的整数,并返回结果。如果传递的参数是整数,则不会舍入该值。 Math.floor(7/2)=3 //强制向下取整,floor() 方法返回小于等于x的最大整数。如果传递的参数是一个整数,该值不变 parseInt(7/2)=3 //强行转化,得出最小整数,同Math.floor方法。parseInt() 函数可解析一个字符串,并返回一个整数。
Copy after login

Recommended study: "JavaScript basic tutorial

The above is the detailed content of What are the methods of javascript division and rounding?. 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!