Home  >  Article  >  Web Front-end  >  What are the methods for rounding decimals in js? (Picture and text tutorial)

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

亚连
亚连Original
2018-05-18 16:25:352307browse

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)

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

js: Math.ceil(7/2)

3, Rounding.

js: Math.round(7/2)

4, round down

js: Math.floor(7/2)

5. Generate random numbers

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

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!

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