Home > Web Front-end > JS Tutorial > body text

What are the methods for rounding decimals in js? (Picture and text tutorial)

亚连
Release: 2018-05-18 16:25:35
Original
2309 people have browsed it

The following are the methods I have compiled for you to round decimals in js? , interested students can check it out.

1. Discard the decimal part and keep the integer part

js:parseInt(7/2)
Copy after login

2. Round up, if there is a decimal, add 1 to the integer part

js: Math.ceil(7/2)
Copy after login

3, Rounding.

js: Math.round(7/2)
Copy after login

4, round down

js: Math.floor(7/2)
Copy after login

5. Generate random numbers

js:Math.random()*10  0-9的随机数
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Vue.jsSummary on the use of form controls

##js Transferjson parameter to controller step analysis

$http service Post method transferjson parameter case detailed explanation

The above is the detailed content of What are the methods for rounding decimals in js? (Picture and text tutorial). 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template