惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - Franky
有赞技术团队
有赞技术团队
Last Week in AI
Last Week in AI
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
aimingoo的专栏
aimingoo的专栏
Recent Announcements
Recent Announcements
雷峰网
雷峰网
T
Tor Project blog
博客园_首页
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Register - Security
The Register - Security
T
The Blog of Author Tim Ferriss
Recorded Future
Recorded Future
V
Vulnerabilities – Threatpost
Project Zero
Project Zero
J
Java Code Geeks
AWS News Blog
AWS News Blog
Security Latest
Security Latest
Spread Privacy
Spread Privacy
T
Threatpost
博客园 - 三生石上(FineUI控件)
I
Intezer
G
Google Developers Blog
Scott Helme
Scott Helme
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The Hacker News
The Hacker News
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
NISL@THU
NISL@THU
A
Arctic Wolf
F
Full Disclosure
P
Proofpoint News Feed
G
GRAHAM CLULEY
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
N
Netflix TechBlog - Medium
C
Cybersecurity and Infrastructure Security Agency CISA
T
Threat Research - Cisco Blogs
B
Blog
IT之家
IT之家
MongoDB | Blog
MongoDB | Blog
L
LangChain Blog
Know Your Adversary
Know Your Adversary

博客园 - 轻松

css div 垂直居中 How to create custom methods for use in spring security expression language annotations How to check “hasRole” in Java Code with Spring Security? Android 显示/隐藏 应用图标 Android 当媒体变更后,通知其他应用重新扫描 Dynamically loading an external JavaScript or CSS file android 脸部抠图 IIS + TOMCAT 注意事项 textbox icon jquery 插件 让IE支持HTML5的Canvas vba 生成euc文件的方法 - 轻松 - 博客园 [原创]让Allvidoes插件支持 优酷(www.youku.com)的视频 ORACLE ERROR CODE代表的意思 http://hi.baidu.com/czh0221/blog/item/9f0447e719644a2ab83820c6.html [转]利用location的hash值来解决Ajax两大难题 JAVA 调用Web Service的方法 xampp-control中启动Apache时80断口被占用的错误 asp.net mail java获取运行的jar(class)文件的路径
数值项目的格式化 - 轻松 - 博客园
轻松 · 2010-05-14 · via 博客园 - 轻松

数值项目的格式化


//--------------------------------------------
// 删除千分点。

//--------------------------------------------
function removeComma(number) {
 var num = number.replace(new RegExp(",","g"),"");
 if(/^[-+]?[0-9]+(\.[0-9]+)?$/.test(num)) {
  return num;
 } else {
  return number;
 }
}

//--------------------------------------------
//添加千分点。
//--------------------------------------------
function addKannma(number) {

 var num = number.replace(new RegExp(",","g"),"");
 
 // 正负号处理
 var symble = "";
 if(/^([-+]).*$/.test(num)) {
     symble = num.replace(/^([-+]).*$/,"$1");
  num = num.replace(/^([-+])(.*)$/,"$2");
 }

 if(/^[0-9]+(\.[0-9]+)?$/.test(num)) {
  var num = num.replace(new RegExp("^[0]+","g"),"");
  if(/^\./.test(num)) {
   num = "0" + num;
  }

  var decimal = num.replace(/^[0-9]+(\.[0-9]+)?$/,"$1");
  var integer= num.replace(/^([0-9]+)(\.[0-9]+)?$/,"$1");
  
  var re=/(\d+)(\d{3})/

  while(re.test(integer)){ 
   integer =integer.replace(re,"$1,$2")
  }
  return symble + integer + decimal;

 } else {
  return number;
 }
}