有两个版本
版本1:
; 僵尸分享 拾佰仟万判断
MsgBox % n2c(123, 1)
; =============================== 数字转中文函数 ===============================
n2c(n,op:=""){
If (n="s"){
Clipsaved:=ClipboardAll
Clipboard:=""
Send, ^c
ClipWait, 0.5
n:=Clipboard, Clipboard:=Clipsaved, Clipsaved:=""
} Else If (n="c")
n:=Clipboard
n:=StrSplit(n,"."), xs:=RTrim(n[2],"0")?RTrim(n[2],"0"):"0", n:=op="r"?n[1]:(LTrim(n[1],"0")?LTrim(n[1],"0"):"0")
If !(n ~= "^\d*$") ;当不是整数
Return
Else If StrLen(n)>21
Return [{0:"{Value}",1:"",3:"数值超过最大值"}]
Else If (op=""){
arr:=[{0:"{Value}",1:n2c(n "." xs," ")},{0:"{Value}",1:n2c(n "." xs,"d")},{0:"{Value}",1:n2c(n "." xs,"j")}]
Loop 3
arr[A_index,3]:=arr[A_index,1]
Return arr
}
If (op~="[jd]")
a:=StrSplit("零壹贰叁肆伍陆柒捌玖"), b:=StrSplit("拾佰仟万拾佰仟亿拾佰仟兆拾佰仟京拾佰仟垓"), jf:=["角","分","厘","毫"]
Else
a:=StrSplit("〇一二三四五六七八九"), b:=StrSplit("十百千万十百千亿十百千兆十百千京十百千垓")
c:=d:=e:="", k:=StrLen(n)
If (op="r"){
Loop, Parse, n
c.=a[A_LoopField+1]
} Else {
Loop, Parse, n
c.=a[A_LoopField+1] . b[k-A_Index]
if StrLen(c)>(max:=2*b.MaxIndex()+1)
d:=SubStr(c,1,-max+2), c:=SubStr(c,-max+3)
c:=RegExReplace(c,"(〇|零)(十|百|千|拾|佰|仟)","$1"), c:=RegExReplace(c,"(〇|零){4}(万|亿|兆|京)","$1")
c:=RegExReplace(c,"(〇|零)+(万|亿|兆|京)","$2"), c:=RegExReplace(c,"(〇|零)+(?=(〇|零)|$)"), c:=c?c:a[1]
c:=RegExReplace(c,"^" a[2] b[1],b[1])
}
If (op="j"){
If (xs:=SubStr(xs,1,2)){
e:="元"
Loop, Parse, xs
e.=a[A_LoopField+1] jf[A_index]
e:=StrReplace(e, a[1] "角", a[1])
} Else
e:="元整"
} Else If (xs!="0"){
e:="点"
Loop, Parse, xs
e.=a[A_LoopField+1]
}
Return, d . c . e
}
版本2:
MsgBox % ToNum("五十七京六千一百八十一兆〇五十七亿一千七百一十九万三千八百六十") "`n"
. ToNum("五十七京六千一百八十一兆〇五十七亿一千七百一十九万三千八百六十点四五一二")
ToNum(hstr){
static
rstr := "", _str := ""
_arr := {一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,〇:0}
If (RegExMatch(hstr,"点"))
str := StrSplit(hstr,"点")[1], _str := StrSplit(hstr,"点")[2]
Else
str := hstr
str := RegExReplace(str,"〇")
str := RegExReplace(str,"[京兆亿万]","=")
arr := StrSplit(str,"=")
For k,v in arr
{
千位 := (RegExReplace(v,"^.*([一二三四五六七八九])(?=千).*$","$1") = v) ? 0 : _arr[RegExReplace(v,"^.*([一二三四五六七八九])(?=千).*$","$1")]
百位 := (RegExReplace(v,"^.*([一二三四五六七八九])(?=百).*$","$1") = v) ? 0 : _arr[RegExReplace(v,"^.*([一二三四五六七八九])(?=百).*$","$1")]
十位 := (RegExReplace(v,"^.*([一二三四五六七八九])(?=十).*$","$1") = v) ? 0 : _arr[RegExReplace(v,"^.*([一二三四五六七八九])(?=十).*$","$1")]
个位 := (RegExReplace(v,"^.*([一二三四五六七八九])$","$1") = v) ? 0 : _arr[RegExReplace(v,"^.*([一二三四五六七八九])$","$1")]
rstr .= 千位 百位 十位 个位
}
If (_str) {
Loop parse, _str
_rstr .= _arr[A_LoopField]
Return Trim(rstr "." _rstr, "0")
}
Return LTrim(rstr, "0")
}
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。

评论(0)