This example tells the formatted number and amount functionality of JS implementation. Share to everyone for reference, specifically:

** Formatted amount: **

` ````
function number_format (Number, Decimals, DEC_POINT, THOUSANDS_SEP) {/ * * Parameter Description: * Number: To format the number * Decimals: Keep a few decimal * Dec_Point: decimal point symbol * thousands_sep: omit symbol * * / Number = (Number + ') ) .replace (/ [^ 0-9 + -ee.] / g, ''); var n =! isfinite (+ number)? 0: + number, prec =! isfinite (+ DECIMALS)? 0: Math. ABS (Decimals), SEP = (TypeOf Thousands_sep === 'undefined')? ',': thousands_sep, dec = (TypeOf Dec_Point === 'undefined')? '.': Dec_point, s = ', Tofixedfix = Function (N, PREC) {var k = math.pow (10, prec); return '' + math.ceil (n * k) / k;}; s = (PREC? Tofixedfix (n, prec): '' + Math.Round (n)). Split ('.'); Var RE = / (-? \ D +) (\ d {3}) /;While (RE.TEST (S [0])) {s [0] = s [0] .replace (RE, "$ 1" + SEP + "$ 2");} IF ((S [1] || '' How to use: < prec) {
s[1] = s[1] || '';
s[1] += new Array(prec - s[1].length + 1).join('0');
}
return s.join(dec);
}
```

VAR NUM = Number_Format (1234567.089, 2, “.”, ” , // 1, 234, 567.09console.log (NUM);

` `` `

** ** Interested friends can use

` ````
PS: Here you recommend several computing tools for the further reference reference: < prec) {
s[1] = s[1] || '';
s[1] += new Array(prec - s[1].length + 1).join('0');
}
return s.join(dec);
}
var num=number_format(1234567.089, 2, ".", ",");//1,234,567.08
console.log(num)
```

** http://tools.jb51.net/jisuanqi/equ_jisuanqi **

Scientific calculator online usage _ Advanced calculator online calculation: ** http://tools.jb51.net/jisuanqi/jsqkexue **

Online calculator _ standard calculator: ** http: //tools.jb51. Net / jisUNQI / JSQ **

** I hope this article will be designed for the JavaScript programming. help. **

## Please log in to comment

register