Home > Article > Web Front-end > What are the methods for rounding decimals in js? (Picture and text tutorial)
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!