Explanation:
I recently planned to become more proficient in Js, so I had to temporarily give up the good VBScript I had mastered before, and fully use Jscript/Javascript.
I found that both VBs and Js have some functions that both sides do not have...
For example Js does not have functions like formatNumber and formatN*** like VBs.
But Js can use regular expressions almost everywhere. This is my strength and this is what attracts me. Unlike VBs, only the RegExp domain can use regular expressions.
Quote from a book:
The way to really learn a new programming language is to write programs with it.
--JavaScript: The Definitive Guide, 4th Edition
Directory:
1. Content: Number.prototype.formatNumber() source code.
2. Efficiency test
shawl.qiu
2006-10-14
http:/ /blog.csdn.net/btbtd
1. Content: Number.prototype.formatNumber() source code.
linenum
<%
var $num=9876577784321.011
Number.prototype.formatNumber=function(pointPsti){
/*-------------------------------------------------- ---------*
* Javascript formatting digital prototype, By shawl.qiu
* * Client usage: var $num=9876577784321.011; document.write('
' $num.formatNumber(3) '
'); -------------------------------------------------- ----*/
if(this=='')return false;
if(typeof(pointPsti)=='undefined'){
var pointPsti=3;
} else { if(isNaN(pointPsti)){pointPsti=3}; }
var num=this '', numDc='', temp='';
if(num.indexOf('.')>- 1){ ptPs=num.indexOf('.'); numDc=num.substr(ptPs); num=num.substr(0,ptPs); }
;=0;temp =num.substr(i,1), i--);
var re=new RegExp('(.{' pointPsti '})','g'); temp.replace(re,'$1,'); num=''; );
num=num.replace(/^,|,$/,'') numDc;
return num; //shawl.qiu script
} sponse.Write($num. formatNumber(3) '
');
%>
2. Efficiency test
outputs 10,000 times, taking 2797 milliseconds.
Output 5,000 times, taking 1515 milliseconds.
Output 2,000 times, taking 672 milliseconds.
Output 1,000 times, taking 281 milliseconds.
Output 500 times, taking 140 milliseconds.
Output 100 times, taking 16 milliseconds.