北大侠客行MUD论坛

 找回密码
 注册
搜索
热搜: 新手 wiki 升级
查看: 11576|回复: 8

发个中文数字转化的函数

[复制链接]
发表于 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
北大侠客行Mud(pkuxkx.com),最好的中文Mud游戏!
发表于 2010-2-5 10:59:06 | 显示全部楼层
好用
北大侠客行Mud(pkuxkx.com),最好的中文Mud游戏!
发表于 2010-2-5 13:34:16 | 显示全部楼层
我刚问了个i2命令,加上这个可以解决很多问题
北大侠客行Mud(pkuxkx.com),最好的中文Mud游戏!
发表于 2010-8-9 22:50:28 | 显示全部楼层

支持亿及以上For Zmud 4.62

  1. number=%replace(@number,百十,百一十);
  2. m=%pos(亿,@number);
  3. #if @m>0 {number3=%left(@number,@m-1);
  4. number4=%right(@number,@m+1)} {number3="";
  5. number4=@number};
  6. number=@number3;
  7. m=%pos(万,@number);
  8. #if @m>0 {number1=%left(@number,@m-1);
  9. number2=%right(@number,@m+1)} {number1="";
  10. number2=@number};
  11. number=@number1;
  12. number=%replace(@number,"零","0");
  13. number=%replace(@number,"一","1");
  14. number=%replace(@number,"二","2");
  15. number=%replace(@number,"三","3");
  16. number=%replace(@number,"四","4");
  17. number=%replace(@number,"五","5");
  18. number=%replace(@number,"六","6");
  19. number=%replace(@number,"七","7");
  20. number=%replace(@number,"八","8");
  21. number=%replace(@number,"九","9");
  22. number=%replace(@number,十,"*10+");
  23. number=%replace(@number,百,"*100+");
  24. number=%replace(@number,千,"*1000+");
  25. number=%replace(@number," ","");
  26. #if (%rightback(@number,1)="+") {number=%leftback(@number,1)};
  27. #if (%left(@number,1)="*") {number=%right(@number,1)};
  28. number=%eval(@number);
  29. number1=@number;
  30. number=@number2;
  31. number=%replace(@number,"零","0");
  32. number=%replace(@number,"一","1");
  33. number=%replace(@number,"二","2");
  34. number=%replace(@number,"三","3");
  35. number=%replace(@number,"四","4");
  36. number=%replace(@number,"五","5");
  37. number=%replace(@number,"六","6");
  38. number=%replace(@number,"七","7");
  39. number=%replace(@number,"八","8");
  40. number=%replace(@number,"九","9");
  41. number=%replace(@number,十,"*10+");
  42. number=%replace(@number,百,"*100+");
  43. number=%replace(@number,千,"*1000+");
  44. number=%replace(@number," ","");
  45. #if (%rightback(@number,1)="+") {number=%leftback(@number,1)};
  46. #if (%left(@number,1)="*") {number=%right(@number,1)};
  47. number=%eval(@number);
  48. number2=@number;
  49. #math number @number1*10000+@number2;
  50. number3=@number;
  51. number=@number4;
  52. m=%pos(万,@number);
  53. #if @m>0 {number1=%left(@number,@m-1);
  54. number2=%right(@number,@m+1)} {number1="";
  55. number2=@number};
  56. number=@number1;
  57. number=%replace(@number,"零","0");
  58. number=%replace(@number,"一","1");
  59. number=%replace(@number,"二","2");
  60. number=%replace(@number,"三","3");
  61. number=%replace(@number,"四","4");
  62. number=%replace(@number,"五","5");
  63. number=%replace(@number,"六","6");
  64. number=%replace(@number,"七","7");
  65. number=%replace(@number,"八","8");
  66. number=%replace(@number,"九","9");
  67. number=%replace(@number,十,"*10+");
  68. number=%replace(@number,百,"*100+");
  69. number=%replace(@number,千,"*1000+");
  70. number=%replace(@number," ","");
  71. #if (%rightback(@number,1)="+") {number=%leftback(@number,1)};
  72. #if (%left(@number,1)="*") {number=%right(@number,1)};
  73. number=%eval(@number);
  74. number1=@number;
  75. number=@number2;
  76. number=%replace(@number,"零","0");
  77. number=%replace(@number,"一","1");
  78. number=%replace(@number,"二","2");
  79. number=%replace(@number,"三","3");
  80. number=%replace(@number,"四","4");
  81. number=%replace(@number,"五","5");
  82. number=%replace(@number,"六","6");
  83. number=%replace(@number,"七","7");
  84. number=%replace(@number,"八","8");
  85. number=%replace(@number,"九","9");
  86. number=%replace(@number,十,"*10+");
  87. number=%replace(@number,百,"*100+");
  88. number=%replace(@number,千,"*1000+");
  89. number=%replace(@number," ","");
  90. #if (%rightback(@number,1)="+") {number=%leftback(@number,1)};
  91. #if (%left(@number,1)="*") {number=%right(@number,1)};
  92. number=%eval(@number);
  93. number2=@number;
  94. #math number @number1*10000+@number2;
  95. number4=@number;
  96. #math number @number3*100000000+@number4
复制代码
北大侠客行Mud(pkuxkx.com),最好的中文Mud游戏!
发表于 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,然后替换++,+*为+

原帖由 dgda 于 2010-8-9 10:50 PM 发表
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 编辑 ]
北大侠客行Mud(pkuxkx.com),最好的中文Mud游戏!
发表于 2010-9-14 18:38:49 | 显示全部楼层
这个怎么用?
北大侠客行Mud(pkuxkx.com),最好的中文Mud游戏!
发表于 2010-9-15 00:05:19 | 显示全部楼层
原帖由 jimowuqing 于 2010-9-14 06:38 PM 发表
这个怎么用?


比如:
(*)两白银
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看看
北大侠客行Mud(pkuxkx.com),最好的中文Mud游戏!
发表于 2017-5-16 19:33:02 | 显示全部楼层
好用,谢谢!
北大侠客行Mud(pkuxkx.com),最好的中文Mud游戏!
发表于 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好象可以
北大侠客行Mud(pkuxkx.com),最好的中文Mud游戏!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|北大侠客行MUD ( 京ICP备16065414号-1 )

GMT+8, 2024-11-28 05:09 AM , Processed in 0.012553 second(s), 14 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表