JS rounding up

When making requirements, sometimes you need to round up every decimal, and sometimes you need to round off the decimal. The method is as follows:

Just put numbers in brackets, and the WeChat applet can also be used.

//仅取整数部分
Math.floor()
 
//小数进一
Math.ceil()
 
//四舍五入
Math.round()
/*js里没有对小数点后控制多少位的函数,想精确到小数后多少位,并四舍五入,如下)*/
function round(v,e) 
{ 
    var a=1; 
    for(;e>0;a*=10,e--); 
    for(;e<0;a/=10,e++); 
    return Math.round(v*a)/a; 
}

 

Guess you like

Origin blog.csdn.net/bitcser/article/details/105579354