|
发表于 2011-11-14 21:58:49
|
显示全部楼层
function chinese_to_number(str)
if (#str % 2) == 1 then
str = string.sub(str,1,#str-1);
end
result=0
wan=1
unit=1
for i=#str -2 ,0,-2 do
char=string.sub(str,i+1,i+2)
if (char=="十") then
unit=10*wan
if (i==0) then
result=result+unit
elseif _nums[string.sub(str,i-1,i)]==nil then
result=result+unit
end
elseif (char=="甲" and string.sub(str,i+3,i+4)=="子") then
unit=60*wan
wan=60
elseif (char=="百") then
unit=100*wan
elseif (char=="千") then
unit=1000*wan
elseif (char=="万") then
unit=10000*wan
wan=10000
else
if _nums[char]~=nil then
result=result+_nums[char]*unit
end
end
end
return result
end |
|