Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to use JavaScript to make numbers less than 4 digits behind the decimal point make up 0, and ask the gods for an answer!

Function? Formatnumber (value, num){

var? First,? b,? c,? Me;

How to use JavaScript to make numbers less than 4 digits behind the decimal point make up 0, and ask the gods for an answer!

Function? Formatnumber (value, num){

var? First,? b,? c,? Me;

How to use JavaScript to make numbers less than 4 digits behind the decimal point make up 0, and ask the gods for an answer!

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.