阿拉伯数字转换为大写数字的脚本
时间:2008-05-03 来源:剑心通明
<IFRAME name=google_ads_frame marginWidth=0 marginHeight=0 src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-4117525570087365&dt=1209782064453&lmt=1209319864&output=html&slotname=9298919995&correlator=1209782064437&url=http%3A%2F%2Fwww.bsdlover.cn%2Fhtml%2F95%2Fn-795.html&ref=http%3A%2F%2Fwww.bsdlover.cn%2Fhtml%2F6%2Fcategory-catid-6.html&frm=0&cc=100&ga_vid=2475259519912655400.1209782065&ga_sid=1209782065&ga_hid=1470993445&flash=9.0.115.0&u_h=768&u_w=1024&u_ah=715&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameBorder=0 width=250 scrolling=no height=250 allowTransparency></IFRAME>
感谢作者 penny兄
代码:
#!/bin/bash
#[email protected]
#it's ugly, but it works
cconvert(){
declare -a cnum;
declare -a cmag;
cnum[1]="壹"
cnum[2]="贰"
cnum[3]="叁"
cnum[4]="肆"
cnum[5]="伍"
cnum[6]="陆"
cnum[7]="柒"
cnum[8]="拔"
cnum[9]="玖"
cnum[0]="零"
cmag[0]=""
cmag[1]="拾"
cmag[2]="佰"
cmag[3]="仟"
cmag[4]="万"
cmag[5]="拾"
cmag[6]="百"
cmag[7]="千"
tempalpha="$1";
ctempmag=$2;
if [ $tempalpha == "00000000" ] ; then
CSTR="";
return 0;
fi
let templength="${#tempalpha}";
CSTR="";
for ((m=0;m<templength;m++))
do
tempi=${tempalpha:m:1};
let tempj="$templength-$m-1";
if ((( tempi == 0 )) && (( tempj ==4 ))); then
CSTR=$CSTR"万";
elif (( tempi == 0 )); then
CSTR=$CSTR${cnum[0]};
else
CSTR=$CSTR${cnum[$tempi]}${cmag[$tempj]};
fi
done
CSTR=$(echo $CSTR | sed -e 's/零零*/零/g' -e 's/零$//g' -e 's/零零零万//g');
CMAG="";
for ((m=0;m<ctempmag;m++))
do
CMAG=$CMAG"亿";
done
CSTR=$CSTR$CMAG;
}
alpha=$1;
length=${#alpha};
let k="$length/8";
let modl="$length%8";
MYSTR="";
tempstr=${alpha:0:$modl};
if ((modl>0)); then cconvert $tempstr $k; fi
MYSTR=$MYSTR$CSTR;
for ((i=0;i<k;i++))
do
let pos="$i*8+modl";
tempstr=${alpha:$pos:8};
let tempmag="$k-$i-1";
cconvert $tempstr $tempmag;
MYSTR=$MYSTR$CSTR;
done
echo $MYSTR | sed -e 's/亿零万/亿零/g' -e 's/零万/万/g' -e 's/零亿/亿/g' -e 's/零零*/零/g' -e 's/零$//g';
代码:
#!/bin/bash
#[email protected]
#it's ugly, but it works
cconvert(){
declare -a cnum;
declare -a cmag;
cnum[1]="壹"
cnum[2]="贰"
cnum[3]="叁"
cnum[4]="肆"
cnum[5]="伍"
cnum[6]="陆"
cnum[7]="柒"
cnum[8]="拔"
cnum[9]="玖"
cnum[0]="零"
cmag[0]=""
cmag[1]="拾"
cmag[2]="佰"
cmag[3]="仟"
cmag[4]="万"
cmag[5]="拾"
cmag[6]="百"
cmag[7]="千"
tempalpha="$1";
ctempmag=$2;
if [ $tempalpha == "00000000" ] ; then
CSTR="";
return 0;
fi
let templength="${#tempalpha}";
CSTR="";
for ((m=0;m<templength;m++))
do
tempi=${tempalpha:m:1};
let tempj="$templength-$m-1";
if ((( tempi == 0 )) && (( tempj ==4 ))); then
CSTR=$CSTR"万";
elif (( tempi == 0 )); then
CSTR=$CSTR${cnum[0]};
else
CSTR=$CSTR${cnum[$tempi]}${cmag[$tempj]};
fi
done
CSTR=$(echo $CSTR | sed -e 's/零零*/零/g' -e 's/零$//g' -e 's/零零零万//g');
CMAG="";
for ((m=0;m<ctempmag;m++))
do
CMAG=$CMAG"亿";
done
CSTR=$CSTR$CMAG;
}
alpha=$1;
length=${#alpha};
let k="$length/8";
let modl="$length%8";
MYSTR="";
tempstr=${alpha:0:$modl};
if ((modl>0)); then cconvert $tempstr $k; fi
MYSTR=$MYSTR$CSTR;
for ((i=0;i<k;i++))
do
let pos="$i*8+modl";
tempstr=${alpha:$pos:8};
let tempmag="$k-$i-1";
cconvert $tempstr $tempmag;
MYSTR=$MYSTR$CSTR;
done
echo $MYSTR | sed -e 's/亿零万/亿零/g' -e 's/零万/万/g' -e 's/零亿/亿/g' -e 's/零零*/零/g' -e 's/零$//g';
相关阅读 更多 +