首页 > 代码库 > 小写金转换为大写
小写金转换为大写
<body>
<input type="text" id="txt"/><br/>
<input type="button" id="ss" value="http://www.mamicode.com/submit"/><br/>
<input type="text" id="result"/>
</body>
<script type="text/javascript" >
$(function(){
$("#ss").click(function(){
var s=change($("#txt").val());
$("#result").val(s);
})
})
function change(str){
je = "零壹贰叁肆伍陆柒捌玖";
cdw = "万仟佰拾亿仟佰拾万仟佰拾元角分";
var newstring = (str*100).toString();
var newstringlog = newstring.length;
newdw = cdw.substr(cdw.length-newstringlog);
var num0 = 0;
var wan = 0;
var dxje = "";
for(var m=1;m<(newstringlog+1);m++){
var xzf = newstring.substr(m-1,1);
var dzf = je.substr(xzf,1);
var dw = newdw.substr(m-1,1);
if(dzf=="零"){
dzf = "";
wan = 1;
if(dw=="亿"){}
else if(dw=="万"){
dzf="";
wan=1;
}else if(dw=="元"){}
else{dw="";}
num0 = num0+1;
}else{
if(num0-wan>0){
if(dw!="角"){
dzf="零"+dzf;
}
}
num0=0;
}
dxje=dxje+dzf+dw;
}
if(newstring.length!=1){
if(newstring.substr(newstring.length-2)=="00"){
dxje=dxje+"整";
}else{
dxje=dxje;
}
}
return dxje;
}
</script>