100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > js prototype 格式化数字 By shawl.qiu【javascript】

js prototype 格式化数字 By shawl.qiu【javascript】

时间:2022-01-06 17:38:54

相关推荐

js prototype 格式化数字 By shawl.qiu【javascript】

web前端|js教程

js,prototype,格式化数字,By,shawl.qiu

web前端-js教程

说明:

最近打算把 Js 练精点, 只好暂时放弃原来掌握的还行的 VBScript, 全面使用 Jscript/Javascript.

发现 VBs 和 Js 都有些双方没有的功能…

比如 Js 就没有 VBs 的 formatNumber, formatN*** 类的函数.

但是 Js 几乎随处可用 正则, 这是我的长处, 这点特吸引我, 不像 VBs 只有 RegExp 使用域可以使用正则.

asp网站源码如何布置,vscode固定工作目录,ss ubuntu 安装,tomcat启动后宕机,sqlite3时间,我的世界爬虫大作战手机版,php 唯一字符串,SEO优化网站排名推广,音乐网站 jsp 源码,dede模板制作lzw

引用一本书里的一句话:

The way to really learn a new programming language is to write programs with it.

–JavaScript: The Definitive Guide, 4th Edition

c 简单小项目源码下载,vscode中无法显示插件,ubuntu主题没了,tomcat怎么调中文,网页爬虫 程序,php树形菜单的实现,宁波seo排名多少钱,理想网站源码论坛,后台企业网站模板lzw

目录:

1. 内容: Number.prototype.formatNumber() 源代码.

2. 效率测试

网上商城项目源码,vscode的插件无法运行,ubuntu中断安装,j访问不了tomcat,pycharm导入爬虫,php 扫描仪,二七区seo推广公司,logo网站导航源码程序,discuz模板插件免费下载lzw

shawl.qiu

-10-14

/btbtd

1. 内容: Number.prototype.formatNumber() 源代码.

linenum

<%

var $num=9876577784321.011

Number.prototype.formatNumber=function(pointPsti){

/*--------------------------------------------------------*\

* Javascript 格式化数字原型, By shawl.qiu

* 客户端使用: var $num=9876577784321.011; document.write(

+$num.formatNumber(3)+

);

* 服务端使用: 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)+

);

%>

2. 效率测试

输出 10,000 次, 耗时 2797 毫秒.

输出 5,000 次, 耗时 1515 毫秒.

输出 2,000 次, 耗时 672 毫秒.

输出 1,000 次, 耗时 281 毫秒.

输出 500 次, 耗时 140 毫秒.

输出 100 次, 耗时 16 毫秒.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。