Home >Web Front-end >JS Tutorial >How to write js to retain the number of decimal places
This article mainly introduces how to write several decimal places in js. Friends who need it can come and refer to it. I hope it will be helpful to everyone.
is as follows:
//保留小数点后2位 function disposeNumber(value){ if(value == null || value == ""){ return 0; }else if(value.toString().indexOf(".") == -1){ return value; }else{ return round(value, 2); } } function round(v,e){ var t=1; for(;e>0;t*=10,e--); for(;e<0;t/=10,e++); return Math.round(v*t)/t; }
The above is the entire content of this chapter. For more related tutorials, please visit JavaScript video tutorial!