谁可以做一个函数啊?汉字数字转成阿拉伯数字
比如:一百二十八万三千零四十五转成1283045Re:谁可以做一个函数啊?汉字数字转成阿拉伯数字
#ALIAS counter {#forall @lists {#math Abc_1 {@Abc_1+1};Abc_2=%pos(%i,"@Years");#if (@Abc_2<>0) {#math Abc_3 {@Abc_2-2};Def_1=%copy("@Years",@Abc_3,2);#math Abc_4 {(%pos("@Def_1","一二三四五六七八九")+1)/2};Abc_5=1;#loop @Abc_1 {#math Abc_5 {@Abc_5*10}};#math TotalDX {@TotalDX+@Abc_4*@Abc_5}}}}#va lists {十|百|千|万} {十|百|千|万}
#va Years {二千三百七十四} {""}
#va Abc_1 {4} {0}
#va Abc_2 {0} {0}
#va Abc_3 {1} {0}
#va Def_1 {二} {""}
#va Abc_4 {2} {0}
#va Abc_5 {1000} {0}
#va TotalDX {2374} {0}
#va Def_2 {四} {""}
#va Abc_6 {4} {0}
#TRIGGER {^%s饮水:*道行:(*)年} {Years=%1;Abc_1=0;TotalDX=0;#if (%pos("十","@Years")=1) {#math TotalDX {@TotalDX+10}} {counter};#if (%pos("零十","@Years")<>0) {#math TotalDX {@TotalDX+10}};Def_2=%rightback("@Years",2);#math Abc_6 {(%pos("@Def_2","一二三四五六七八九")+1)/2};#math TotalDX {@TotalDX+@Abc_6};#sa 我的道行是: @TotalDX年} {} 519
不过好像有范围限制,具体多少记不清了,自己试试吧
[ Last edited by kugua on 2005-1-17 at 02:19 PM ]
Re:谁可以做一个函数啊?汉字数字转成阿拉伯数字
这么多的编程命令,在什么地方学的?
我看了不少的关于zmud的帮助,都不是很详细`~~
有没有更加详细?推荐一下~chat* thank
Re:谁可以做一个函数啊?汉字数字转成阿拉伯数字
用jscript做,就比较容易了Re:谁可以做一个函数啊?汉字数字转成阿拉伯数字
这个东西......当初没学,现在没空,懒啊......Re:谁可以做一个函数啊?汉字数字转成阿拉伯数字
saviola就知道练功,服!没关系,也好,你的米就是我的米,我的米还是我的米! /**汉字数字转换成阿拉伯数字**/
function ch2num(strnum) {
var num = 0;
if (strnum.indexOf("万") == -1) {
num = str2num(strnum);
} else {
num = str2num(strnum.substr(0,strnum.indexOf("万")))*10000;
num += str2num(strnum.substr(strnum.indexOf("万")+1));
}
function str2num(str) {
var ge, shi, bai, qian;
qian = str.substr(0,str.indexOf("千"));
if (str.indexOf("千") != -1) qian = (qian == "") ? "一" : qian;
str = str.substr(str.indexOf("千")+1);
bai = str.substr(0,str.indexOf("百"));
if (str.indexOf("百") != -1) bai = (bai == "") ? "一" : bai;
str = str.substr(str.indexOf("百")+1);
shi = str.substr(0,str.indexOf("十"));
if (str.indexOf("十") != -1) shi = (shi == "") ? "一" : shi;
ge = str.substr(str.indexOf("十")+1);
ge = ge.replace("零","");
var _n = c2n(ge) + c2n(shi)*10 + c2n(bai)*100 + c2n(qian)*1000;
function c2n(str) {
var tmp = 0;
if (str == "零") tmp = 0;
if (str == "一") tmp = 1;
if (str == "二") tmp = 2;
if (str == "三") tmp = 3;
if (str == "四") tmp = 4;
if (str == "五") tmp = 5;
if (str == "六") tmp = 6;
if (str == "七") tmp = 7;
if (str == "八") tmp = 8;
if (str == "九") tmp = 9;
if (str == "十") tmp = 10;
if (str == "百") tmp = 100;
if (str == "千") tmp = 1000;
if (str == "万") tmp = 10000;
return(tmp);
}
return(_n);
}
return(num);
} 原帖由 <i>tianheng</i> 于 2008-3-11 10:22 PM 发表 <a href="http://advent.pkuxkx.com:1234/forum/redirect.php?goto=findpost&pid=32469&ptid=1173" target="_blank"><img src="http://advent.pkuxkx.com:1234/forum/images/common/back.gif" border="0" alt="" /></a><br />
/**汉字数字转换成阿拉伯数字**/<br />
function ch2num(strnum) {<br />
var num = 0;<br />
if (strnum.indexOf("万"<img src="images/smilies/default/wink.gif" smilieid="4" border="0" alt="" /> == -1) {<br />
num = str2num(strnum);<br />
} else {<br />
num = str2num(strnum.substr(0,strnum.indexOf("万"<img src="images/smilies/default/wink.gif" smilieid="4" border="0" alt="" />) ... <br />
经测试这个不行。
[ 本帖最后由 sure 于 2008-3-12 04:03 PM 编辑 ] var num;
function money(money)
{
var t="一百二十八万三千零四十五";
num=0;
var n=ch2num(t);
world.note(n);
}
function ch2num(ch)
{
var r,str;
r=ch.indexOf("万");
if(r>-1)
{
str=ch.substr(0,r);
num+=parseInt(ch2num(str))*10000;
if(ch.length>r+1)
{
ch=ch.substr(r+1,ch.length);
ch2num(ch);
}
}
else
{
r=ch.indexOf("千");
if(r>-1)
{
str=ch.substr(0,r);
num+=parseInt(c2n(str))*1000;
if(ch.length>r+1)
{
ch=ch.substr(r+1,ch.length);
ch2num(ch);
}
}
else
{
r=ch.indexOf("百");
if(r>-1)
{
str=ch.substr(0,r);
num+=parseInt(c2n(str))*100;
if(ch.length>r+1)
{
ch=ch.substr(r+1,ch.length);
ch2num(ch);
}
}
else
{
r=ch.indexOf("十");
if(r>-1)
{
if(r==0)
{
num+=10;
}
else
{
str=ch.substr(0,r);
num+=parseInt(c2n(str))*10;
}
if(ch.length>r+1)
{
ch=ch.substr(r+1,ch.length);
ch2num(ch);
}
}
else
{
num+=parseInt(c2n(ch));
}
}
}
}
return num;
}
function c2n(str)
{
var str1;
str1=str.replace("一","1");
str1=str1.replace("二","2");
str1=str1.replace("三","3");
str1=str1.replace("四","4");
str1=str1.replace("五","5");
str1=str1.replace("六","6");
str1=str1.replace("七","7");
str1=str1.replace("八","8");
str1=str1.replace("九","9");
str1=str1.replace("十","1");
str1=str1.replace("零","");
return str1;
} strong
页:
[1]
2