<div class="codetitle"> <span><a style="CURSOR: pointer" data="58318" class="copybut" id="copybut58318" onclick="doCopy('code58318')"><u>复制代</u></a></span> 代码如下:</div> <div class="codebody" id="code58318"> <br><script type="text/javascript"><br> var format = function (number, form) {<br> var form = form.split('.'),number = ''number,numbers =number.split('.')<br> , leftnumber =数値[0 ].split('')<br> , exec = function (lastMatch) {<br> if (lastMatch == '0' || lastMatch == '#') {<br> if (leftnumber.length) {<br> return leftnumber.pop();<br> } else if (lastMatch == '0') {<br> return lastMatch;<br> } else {<br> return '';<br> }<br> } else {<br> return lastMatch;<br> }<br> }, string<br><br> string = Forms[0].split('').reverse().join('').replace( /./g, exec).split('').reverse().join('');<br> string = leftnumber.join('') string;<br><br> if (forms[1] && フォーム[1].length) {<br> leftnumber = (numbers[1] && ナンバー[1].length) ? numbers[1].split('').reverse() : [];<br> string = '.' Forms[1].replace(/./g, exec);<br> }<br> return string.replace(//.$/, '');<br>};<br>alert(format(123) , '#.00')) //输出 123.00 <br>alert(format(123, '0.##')) //输出 123 <br>alert( 123, '0000.00 ')) //输出0123.00 <br>alert(format(123456, '###,###.00')) //输出 123,456.00 <br></script><br> </div>