//encapsulate JS thousand bits plus commas and delete commasAlert (Format (2545678754.020001))//2,545,678,754.03Alert (Format (-2545678754.020001))//-2,545,678,754.02Alert (Format (2545678754.000000000009));//when the value is long, there will be a problem with the number being intercepted.Alert (Delformat (' 2,545,678,754.03 '));//2545678754.03Alert (Delformat (' -2,545,678,754.03 '));//-2545678754.03 functionformat (num) {varSnum=num.tofixed (2) + ",//leave the incoming value "rounded" for 2 decimal placesre=/(\d+) (\d{3})/; if(/\.\d{3}/.test (num+ ") ){ if(Snum.charat (0)! = '-'){ //if the value passed in is not more than two decimal places, move forward 1 to reserve 2 decimal places, such as: 1.2400001-1.25Snum=snum.substring (0,snum.length-1) + (parseint (Snum.slice (-1)) +1); } } //There are too many things to do in the 1, such as 0.999-0.0009 while(Re.test (snum)) {Snum=snum.replace (Re, ' $1,$2 ')); } returnSnum; } functionDelformat (snum) {returnSnum.replace (/,/g, "); }
Encapsulate JS thousand bits plus commas and delete commas