<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 = 함수(숫자, 형식) {<br> var form = form.split('.'), number = '' 숫자, 숫자 = 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> '' 반환;<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 = (숫자[1] && 숫자[1].length) ? 숫자[1].split('').reverse() : [];<br> 문자열 = '.' form[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(format(123, '0 000.00 ')) //출출 0123.00 <br>alert(format(123456, '###,###.00')) //输流 123,456.00 <br></script><br> </div>