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

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
T
Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
Intezer
C
Cyber Attacks, Cyber Crime and Cyber Security
The Register - Security
The Register - Security
量子位
Security Latest
Security Latest
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
MyScale Blog
MyScale Blog
J
Java Code Geeks
Apple Machine Learning Research
Apple Machine Learning Research
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
Spread Privacy
Spread Privacy
Jina AI
Jina AI
博客园 - 【当耐特】
P
Palo Alto Networks Blog
Last Week in AI
Last Week in AI
SecWiki News
SecWiki News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
G
GRAHAM CLULEY
宝玉的分享
宝玉的分享
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
有赞技术团队
有赞技术团队
T
Tor Project blog
H
Hacker News: Front Page
A
Arctic Wolf
NISL@THU
NISL@THU
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
V
V2EX
N
News and Events Feed by Topic
Webroot Blog
Webroot Blog
Know Your Adversary
Know Your Adversary
P
Privacy International News Feed
I
InfoQ
D
Docker
L
LINUX DO - 最新话题
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
U
Unit 42

博客园 - 小二哥

Linq To SQL 针对单张表,有关系的2张表做查询 请问:MOSS使用中机器名与IP地址的问题 MOSS: 如何根据AD帐号判断该用户是否属于网站用户? 在SQL数据库中构造树,直接显示在.Net的DropDownList里 今天解决了K2工作流的,会签与并签问题 郁闷了半个下午的javascript 滑动条的风格控制 DropDownList的SelectedValue和SelectedIndex asp.net页面的Page_Load执行两次 分析器错误:访问被拒绝....... 论坛登录页面 iframe自适应问题 今天遇到的几个问题以及解决方法 K2自定义工作流程 .Net中几个容易混淆的概念 郁闷到极点了,VSTO2005问题 ajax实现无刷新两级联动DropDownList 如何从XML字符串获取DataSet Ajax的简单配置与应用.
钱额的大小写转换的JS代码
小二哥 · 2006-11-09 · via 博客园 - 小二哥

特别是进行财务相关的项目时,一般客户都希望会有大小写的转换功能. 现在提供一个js代码,
来源不详.
资源共享嘛,有现成的就没必要再自己去写了,呵呵!
我自己实验了一下,还可以,现在发布出来,以方便大家.

源代码如下:


<script>
function regInput(reg)
{
var srcElem = event.srcElement
var oSel = document.selection.createRange()
oSel 
= oSel.duplicate()
oSel.text 
= ""
var srcRange = srcElem.createTextRange()
oSel.setEndPoint(
"StartToStart", srcRange)
var num = oSel.text + String.fromCharCode(event.keyCode) + srcRange.text.substr(oSel.text.length)
event.returnvalue 
= reg.test(num)
}


function chineseNumber(num)
{
if (isNaN(num) || num > Math.pow(1012)) return ""
var cn = "零壹贰叁肆伍陆柒捌玖"
var unit = new Array("拾佰仟""分角")
var unit1= new Array("万亿""")
var numArray = num.toString().split(".")
var start = new Array(numArray[0].length-12)

function toChinese(num, index)
{
var num = num.replace(/\d/g, function ($1)
{
return cn.charAt($1)+unit[index].charAt(start--%4 ? start%4 : -1)
}
)
return num
}


for (var i=0; i<numArray.length; i++)
{
var tmp = ""
for (var j=0; j*4<numArray[i].length; j++)
{
var strIndex = numArray[i].length-(j+1)*4
var str = numArray[i].substring(strIndex, strIndex+4)
var start = i ? 2 : str.length-1
var tmp1 = toChinese(str, i)
tmp1 
= tmp1.replace(/(零.)+/g, "").replace(/+$/"")
tmp1 
= tmp1.replace(/^壹拾/"")
tmp 
= (tmp1+unit1[i].charAt(j-1)) + tmp
}

numArray[i] 
= tmp 
}


numArray[
1= numArray[1? numArray[1] : ""
numArray[
0= numArray[0? numArray[0]+"" : numArray[0], numArray[1= numArray[1].replace(/^+/"")
numArray[
1= numArray[1].match(//? numArray[1] : numArray[1]+""
return numArray[0]+numArray[1]
}


function aNumber(num)
{
var numArray = new Array()
var unit = "亿万圆$"
for (var i=0; i<unit.length; i++)
{
var re = eval("/"+ (numArray[i-1? unit.charAt(i-1) : ""+"(.*)"+unit.charAt(i)+"/")
if (num.match(re))
{
numArray[i] 
= num.match(re)[1].replace(/^/"壹拾")
numArray[i] 
= numArray[i].replace(/[零壹贰叁肆伍陆柒捌玖]/g, function ($1)
{
return "零壹贰叁肆伍陆柒捌玖".indexOf($1)
}
)
numArray[i] 
= numArray[i].replace(/[分角拾佰仟]/g, function ($1)
{
return "*"+Math.pow(10"分角 拾佰仟 ".indexOf($1)-2)+"+"
}
).replace(/^\*|\+$/g, "").replace(//"0")
numArray[i] 
= "(" + numArray[i] + ")*"+Math.ceil(Math.pow(10, (2-i)*4))
}

else numArray[i] = 0
}

return eval(numArray.join("+"))
}

</script>

<input id=up size=60 onkeypress="regInput(/^\d{0,12}(\.\d{0,2})?$/)"><button onclick="lw.value = chineseNumber(up.value)">转为大写</button><br>
<input id=lw size=60 value="壹仟壹佰壹拾壹圆整"><button onclick="up.value = aNumber(lw.value)">转为小写</button> 

我自己在.net下测试了一下,小写转大写没问题,但大写转小写就有点问题了.
我把它写在了一个js文件里了.