js⼩写数字转⼤写(正则表达式)
<script language="javascript">
//思想:把不是⾃⼰想要的东西构造成想要的东西 为⾃⼰创造条件
//数的读法:1 每四个为⼀级 2 级尾的零不需要读出 3 ⾮零数之间不论有⼏个零都只读⼀个零
var daxieshuzhu=new Array("零","壹","贰","参","肆","伍","陆","柒","捌","玖");
var danwei=new Array("仟","佰","拾","");
var dadanwei=new Array(" ","万","亿","万亿");
var input=new Array();
var zhuanhuan=function(){
this.input=new Array();  //定义容器接收传⼊串
this.jsq=0;    //计算器,定位万亿
this.output=new Array();  //定义容器存放转换后的串
this.daxiezhuanhuan=function(){
this.strtemp="";
for(var jwq=0;jwq<this.input.length;jwq++){ //转换⼤写并加上单位
this.strtemp+=daxieshuzhu[this.input[jwq]]+danwei[jwq];
}
this.strtemp+=" ";
<=/(零/D)+/g;
this.strtemp=,"零");  //把多个连接的零化成⼀个零
<=/零$/g;js正则表达式判断数字
this.strtemp=,"");  //把级尾的零去掉
if(this.strtemp!=""){
this.output[this.jsq]=place(" ","")+dadanwei[this.jsq];
}
else{
this.output[this.jsq]=place(" ","");
}
this.jsq++;
}
this.taifen=function(input,pb){
this.pb=pb;
this.input=input;
var Ainput=new Array();
var Atemp=new Array(0,0,0,0);
for(var temp=this.input.length-1,temp2=3,jwq=0;temp>=0;temp--,temp2--){ //拆分数字串并构造成每4个⼀组,不⾜4个以0代替    if(temp2<0){
temp2=3;
}
Atemp[temp2]=input.substr(temp,1);
if((temp2%4)==0){
Ainput[jwq]=Atemp;
jwq++;
Atemp=new Array(0,0,0,0);
}
else if(temp==0){
Ainput[jwq]=Atemp;
}
}
if(this.pb==1){
var Ainput2=new Array();
for(var temp=1;temp<Ainput[0].length;temp++){
Ainput2[temp-1]=Ainput[0][temp];
}
Ainput2[3]=0;
Ainput=new Array(Ainput2);
return this.zhuanhuandaxie(Ainput,this.pb);
}
else{
return this.zhuanhuandaxie(Ainput,this.pb);
}
}
this.zhuanhuandaxie=function(Ainput,pb){
this.pb=pb;
this.Ainput=Ainput;
for(var temp=0;temp<this.Ainput.length;temp++){ //循环传⼊数字串并传化为⼤写
this.input=Ainput[temp];
this.daxiezhuanhuan();
}
return this.chongzhu(this.output,this.pb);
}
this.chongzhu=function(output,pb){
this.pb=pb;
this.output=output;
this.Stroutput="";
for(var temp=this.output.length-1;temp>=0;temp--){ //重新组合数据串
this.Stroutput+=this.output[temp];
}
if(this.pb==1){
return place("仟","⾓").replace("佰","分").replace("拾","厘");
}
else{
<=/^零/g;
this.Stroutput=,""); //清除开头的零
return this.Stroutput;
}
}
}
var input=prompt("请输⼊⼀个数字串:",0); //输⼊
var xiaoshu=0;
var re=/^0+/g;
var xiaoshu=0;
var output="",output2="";
place(re,"");
place(",","");
var chafen=new Array();  //定义容器存放整数跟⼩数位
chafen=input.split(".");
if(chafen.length==2){
xiaoshu=chafen[1];
}
input=chafen[0];
var myzhuanhuan=new zhuanhuan();
output=myzhuanhuan.taifen(input,0);
if(xiaoshu!=0){
for(var temp=3-xiaoshu.length;temp>0;temp--){  //构造成⼩数位为三位不⾜三位以0代替    xiaoshu+="0";
}
var myzhuanhuan=new zhuanhuan();
output2=myzhuanhuan.taifen(xiaoshu,1);
}
if(output!="" && output2!=0){ //判断整数是否为零 //输出
alert((output+"圆"+output2).replace(" ",""));
}
else{
if(output2==0){
alert((output+"圆").replace(" ",""));
}
else{
var re=/^零/g;
place(re,""));
}
}
</script>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。