Home>

js to achieve thousand sign conversion

function fmoney (s, n)
{
 n=n>0&&n<= 20?n:2;
 s=parsefloat ((s + "") .replace (/[^ \ d \ .-]/g, "")). tofixed (n) + "";
 var l=s.split (".") [0] .split (""). reverse (),   r=s.split (".") [1];
 var t="";
 for (var i=0;i<l.length;i ++)
 {
   t +=l [i] + ((i + 1)%3 == 0&&(i + 1)!=l.length?",":"");
 }
 return t.split (""). reverse (). join ("") + "." + r;
 }

Use var amount=fmoney (123456.78,2);

console.log (amount);

Results:123,456.78

  • Previous PHP implements a method for reorganizing a two-dimensional array of MySQL duplicate IDs into a three-dimensional array
  • Next JS traverse all object attributes and implementation methods of the page