Function? Formatnumber (value, num){
var? First,? b,? c,? Me;
Function? Formatnumber (value, num){
var? First,? b,? c,? Me;
Answer? =? value . tostring();
b? =? a.indexOf(" . ");
c? =? A. length;
What if? (num? ==? 0)? {
What if? (b? ! =? - 1)? {
Answer? =? a.substring(0,b);
}
}? Or what? {//If there is no decimal point,
What if? (b? ==? - 1)? {
Answer? =? Answer? +? ".";
For what? (me? =? 1; ? Me? & lt=? num? i++)? {
Answer? =? Answer? +? "0";
}
}? Or what? {//There is a decimal point; if it exceeds the digits, it will be automatically intercepted; Otherwise, 0 will be added.
Answer? =? a.substring(0,b? +? num? +? 1);
For what? (me? =? c; ? Me? & lt=? b? +? num? i++)? {
Answer? =? Answer? +? "0";
}
}
}
Return? a;
}
alert(formatnumber(3. 1,4)); //How to use it. The first parameter is the decimal number to be converted, and the second is the number of digits.