sauron 发表于 2010-2-4 20:36:01

发个中文数字转化的函数

不支持亿
--中文大写数字
function transnumberc(str)
if str=="" then return 0 end
local a,b=string.find(str,"万")
if a==nil then
local strtemp=string.gsub(str,"零","")
local res=0
a,b=string.find(strtemp,"^.+千")
if a~=nil then
   res=res+getnumberfromchinese(string.sub(strtemp,1,2))*1000
   strtemp=string.sub(strtemp,b+1)
end
a,b=string.find(strtemp,"^.+百")
if a~=nil then
   res=res+getnumberfromchinese(string.sub(strtemp,1,2))*100
   strtemp=string.sub(strtemp,b+1)
end
a,b=string.find(strtemp,"^.*十")
if a~=nil then
   if b~=2 then
    res=res+getnumberfromchinese(string.sub(strtemp,1,2))*10
   else
    res=res+10
   end
   strtemp=string.sub(strtemp,b+1)
end
if strtemp~=nil then
   res=res+getnumberfromchinese(strtemp)
end
return res
else
return transnumberc(string.sub(str,1,a-1))*10000+transnumberc(string.sub(str,b+1))
end
end
function getnumberfromchinese(str)
if str=="一" then return 1 end
if str=="二" then return 2 end
if str=="三" then return 3 end
if str=="四" then return 4 end
if str=="五" then return 5 end
if str=="六" then return 6 end
if str=="七" then return 7 end
if str=="八" then return 8 end
if str=="九" then return 9 end
return 0
end

killunix 发表于 2010-2-5 10:59:06

好用

gocold 发表于 2010-2-5 13:34:16

我刚问了个i2命令,加上这个可以解决很多问题

dgda 发表于 2010-8-9 22:50:28

支持亿及以上For Zmud 4.62

number=%replace(@number,百十,百一十);
m=%pos(亿,@number);
#if @m>0 {number3=%left(@number,@m-1);
number4=%right(@number,@m+1)} {number3="";
number4=@number};
number=@number3;
m=%pos(万,@number);
#if @m>0 {number1=%left(@number,@m-1);
number2=%right(@number,@m+1)} {number1="";
number2=@number};
number=@number1;
number=%replace(@number,"零","0");
number=%replace(@number,"一","1");
number=%replace(@number,"二","2");
number=%replace(@number,"三","3");
number=%replace(@number,"四","4");
number=%replace(@number,"五","5");
number=%replace(@number,"六","6");
number=%replace(@number,"七","7");
number=%replace(@number,"八","8");
number=%replace(@number,"九","9");
number=%replace(@number,十,"*10+");
number=%replace(@number,百,"*100+");
number=%replace(@number,千,"*1000+");
number=%replace(@number," ","");
#if (%rightback(@number,1)="+") {number=%leftback(@number,1)};
#if (%left(@number,1)="*") {number=%right(@number,1)};
number=%eval(@number);
number1=@number;
number=@number2;
number=%replace(@number,"零","0");
number=%replace(@number,"一","1");
number=%replace(@number,"二","2");
number=%replace(@number,"三","3");
number=%replace(@number,"四","4");
number=%replace(@number,"五","5");
number=%replace(@number,"六","6");
number=%replace(@number,"七","7");
number=%replace(@number,"八","8");
number=%replace(@number,"九","9");
number=%replace(@number,十,"*10+");
number=%replace(@number,百,"*100+");
number=%replace(@number,千,"*1000+");
number=%replace(@number," ","");
#if (%rightback(@number,1)="+") {number=%leftback(@number,1)};
#if (%left(@number,1)="*") {number=%right(@number,1)};
number=%eval(@number);
number2=@number;
#math number @number1*10000+@number2;
number3=@number;
number=@number4;
m=%pos(万,@number);
#if @m>0 {number1=%left(@number,@m-1);
number2=%right(@number,@m+1)} {number1="";
number2=@number};
number=@number1;
number=%replace(@number,"零","0");
number=%replace(@number,"一","1");
number=%replace(@number,"二","2");
number=%replace(@number,"三","3");
number=%replace(@number,"四","4");
number=%replace(@number,"五","5");
number=%replace(@number,"六","6");
number=%replace(@number,"七","7");
number=%replace(@number,"八","8");
number=%replace(@number,"九","9");
number=%replace(@number,十,"*10+");
number=%replace(@number,百,"*100+");
number=%replace(@number,千,"*1000+");
number=%replace(@number," ","");
#if (%rightback(@number,1)="+") {number=%leftback(@number,1)};
#if (%left(@number,1)="*") {number=%right(@number,1)};
number=%eval(@number);
number1=@number;
number=@number2;
number=%replace(@number,"零","0");
number=%replace(@number,"一","1");
number=%replace(@number,"二","2");
number=%replace(@number,"三","3");
number=%replace(@number,"四","4");
number=%replace(@number,"五","5");
number=%replace(@number,"六","6");
number=%replace(@number,"七","7");
number=%replace(@number,"八","8");
number=%replace(@number,"九","9");
number=%replace(@number,十,"*10+");
number=%replace(@number,百,"*100+");
number=%replace(@number,千,"*1000+");
number=%replace(@number," ","");
#if (%rightback(@number,1)="+") {number=%leftback(@number,1)};
#if (%left(@number,1)="*") {number=%right(@number,1)};
number=%eval(@number);
number2=@number;
#math number @number1*10000+@number2;
number4=@number;
#math number @number3*100000000+@number4

oolong 发表于 2010-8-10 07:46:43

xxxxx=%eval( %replace( %replace( (0+%replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %1, "零", "*0+"), "十", "*10+"), "百", "*100+"), "千", "*1000+"), "万", "*10000+"), "六", "6"), "一", "1"), "二", "2"), "三", "3"), "四", "4"), "五", "5"), "七", "7"), "八", "8"), "九", "9")+0), "++", "+"), "+*", "+"))


亿没有遇到过...没写,象楼主要考虑左边*,右边+,我是左边0+,右边+0,然后替换++,+*为+hz6

原帖由 dgda 于 2010-8-9 10:50 PM 发表 http://edu.pkuxkx.com:8082/forum/images/common/back.gif
number=%replace(@number,百十,百一十);
m=%pos(亿,@number);
#if @m>0 {number3=%left(@number,@m-1);
number4=%right(@number,@m+1)} {number3="";
number4=@number};
number=@number3;
m=%pos(万,@number); ...

[ 本帖最后由 oolong 于 2010-8-10 07:50 AM 编辑 ]

jimowuqing 发表于 2010-9-14 18:38:49

这个怎么用?

oolong 发表于 2010-9-15 00:05:19

原帖由 jimowuqing 于 2010-9-14 06:38 PM 发表 http://www.pkuxkx.com/forum/images/common/back.gif
这个怎么用?

比如:
(*)两白银
silver=%eval( %replace( %replace( (0+%replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %1, "零", "*0+"), "十", "*10+"), "百", "*100+"), "千", "*1000+"), "万", "*10000+"), "六", "6"), "一", "1"), "二", "2"), "三", "3"), "四", "4"), "五", "5"), "七", "7"), "八", "8"), "九", "9")+0), "++", "+"), "+*", "+"))


然后#sh @silver看看

wmee 发表于 2017-5-16 19:33:02

好用,谢谢!

hluse 发表于 2021-4-10 20:06:11

oolong 发表于 2010-9-15 12:05 AM
比如:
(*)两白银
silver=%eval( %replace( %replace( (0+%replace( %replace( %replace( %replace( %rep ...

zmud4.62不行
5.5好象可以
页: [1]
查看完整版本: 发个中文数字转化的函数