In JS, math. Round can be used to round integers. If you need to implement precise decimal places, you need to write a custom function.
Method 1:
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;
}
In the parameter, V indicates the number of digits to be retained. e indicates the value to be converted.
Note: If you use a user control, this JS cannot be written in the ascx file, and it should be written in the aspx file using this user control.
Method 2:
Function formatnumber (srcstr, nafterdot ){
VaR srcstr, nafterdot;
VaR resultstr, nten;
Srcstr = "" + srcstr + "";
Strlen = srcstr. length;
Dotpos = srcstr. indexof (".", 0 );
If (dotpos =-1 ){
Resultstr = srcstr + ".";
For (I = 0; I <nafterdot; I ++ ){
Resultstr = resultstr + "0 ";
}
}
Else {
If (strlen-dotpos-1)> = nafterdot ){
Nafter = dotpos + nafterdot + 1;
Nten = 1;
For (j = 0; j <nafterdot; j ++ ){
Nten = nten * 10;
}
Resultstr = math. Round (parsefloat (srcstr) * nten)/nten;
}
Else {
Resultstr = srcstr;
For (I = 0; I <(nafterdot-strlen + dotpos + 1); I ++ ){
Resultstr = resultstr + "0 ";
}
}
}
Return resultstr;
}