- 论坛徽章:
- 0
|
如何使小数金额转化为银行金状态?
//判断输入数是否有小数点,有,返回1,没有返回0
judge_dec()
{
echo $1|awk '{
if ($1~/\./)
print 1
else
print 0
}'
}
//返回输入数每个数字对应的大写汉字
numtochar()
{
numlist=`expr $1 + 1`
chinese="零 壹 贰 叁 肆 伍 陆 柒 捌 玖"
echo $chinese|awk '{print $"'$numlist'"}'
}
//返回输入数每个数字对应的人名币单位
numtoRMB()
{
numlist=`expr $1 + 1`
rmb="元 拾 佰 仟 万 拾 佰 仟 亿 拾 佰 仟"
echo $rmb|awk '{print $"'$numlist'"}'
}
numtochinese()
{
num=$1
str=""
dict_ret=`judge_dec $num`
if [ "$dict_ret" = "0" ];then
echo "*****"
intenumtochina $1
echo "*****"
else
echo "%%%%%"
decinumtochina $1
echo "%%%%%"
fi
}
//小数点后的数字转换
decinumtochina()
{
len=`echo $1|awk '{print length($1)}'`
len=`expr $len - 1`
deci_num=`echo $1 $len|awk '{print substr($1,$2,2)}'`
len=`expr $len - 2`
inte_num=`echo $1 $len|awk '{print substr($1,1,$2)}'`
str=`intenumtochina $inte_num`
jnum=`echo $deci_num|awk '{print substr($1,1,1)}'`
jstr=`numtochar $jnum`"½Ç"
fnum=`echo $deci_num|awk '{print substr($1,2,1)}'`
fstr=`numtochar $fnum`"·Ö"
str=$str$jstr$fstr
echo $str
}
//小数点前的整数转换
intenumtochina()
{
i=1
num=$1
ChinaStr=""
len=`echo $num|awk '{print length($1)}'`
len1=`echo $num|awk '{print length($1)}'`
while [ $i -le $len ]; do
snum=`echo $num $i|awk '{printf substr($1,$2,1)}'`
i=`expr $i + 1`
len1=`expr $len1 - 1`
if [ $snum -eq 0 ];then
ChinaStr=$ChinaStr`numtochar $snum`
else
ChinaStr=$ChinaStr`numtochar $snum``numtoRMB $len1`
fi
done
echo $ChinaStr|sed 's/Á&Á&*/Á&/g'
}
numtochinese 43885.06
numtochinese 4578885 |
|