色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

js prototype 格式化數(shù)字 By shawl.qiu

說明:
最近打算把 Js 練精點, 只好暫時放棄原來掌握的還行的 VBScript, 全面使用 Jscript/Javascript. 
發(fā)現(xiàn) VBs 和 Js 都有些雙方?jīng)]有的功能...
比如 Js 就沒有 VBs 的 formatNumber, formatN*** 類的函數(shù). 
但是 Js 幾乎隨處可用 正則, 這是我的長處, 這點特吸引我, 不像 VBs 只有 RegExp 使用域可以使用正則.

引用一本書里的一句話:
The way to really learn a new programming language is to write programs with it.
--JavaScript: The Definitive Guide, 4th Edition

目錄:
1. 內(nèi)容: Number.prototype.formatNumber() 源代碼.
2. 效率測試

shawl.qiu 
2006-10-14
http://blog.csdn.NET/btbtd

1. 內(nèi)容: Number.prototype.formatNumber() 源代碼.

linenum 
復(fù)制代碼 代碼如下:
<%  
    var $num=9876577784321.011  
        Number.prototype.formatNumber=function(pointPsti){  
        /*--------------------------------------------------------*/    
         *    Javascript 格式化數(shù)字原型, By shawl.qiu  
         *    客戶端使用: var $num=9876577784321.011; document.write('<br/>'+$num.formatNumber(3)+'<br/>');  
         *    服務(wù)端使用: var $num=9876577784321.011; Response.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); }  
            for(var i=num.length-1; i>=0;temp+=num.substr(i,1), i--);  
            var re=new RegExp('(.{'+pointPsti+'})','g');  
                temp=temp.replace(re,'$1,'); num='';                  
            for(var i=temp.length-1; i>=0; num+=temp.substr(i,1), i--);  
                num=num.replace(/^/,|/,$/,'')+numDc;  
            return num; // shawl.qiu script  
        }  
            Response.Write($num.formatNumber(3)+'<br/>');  
%> 

2. 效率測試

輸出 10,000 次, 耗時 2797 毫秒. 
輸出 5,000 次, 耗時 1515 毫秒. 
輸出 2,000 次, 耗時 672 毫秒. 
輸出 1,000 次, 耗時 281 毫秒. 
輸出 500 次, 耗時 140 毫秒. 
輸出 100 次, 耗時 16 毫秒. 

JavaScript技術(shù)js prototype 格式化數(shù)字 By shawl.qiu,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 综艺| 开平市| 宜章县| 德格县| 宁远县| 上蔡县| 弥勒县| 镇远县| 桃源县| 泗洪县| 平江县| 随州市| 鸡东县| 黔南| 乐安县| 芒康县| 卓尼县| 襄樊市| 达孜县| 三穗县| 内丘县| 台安县| 图们市| 乾安县| 灌南县| 吉木萨尔县| 莆田市| 柯坪县| 都江堰市| 武隆县| 大安市| 苍溪县| 浑源县| 老河口市| 中阳县| 虎林市| 白山市| 定陶县| 松阳县| 辽源市| 丁青县|