回复 1# scorpio1102
楼主的AU3语法基础有待提高呀!
没事做按你给出的代码,自己琢磨了一个,你自己再扩展吧!
Local $Number = '55,778.20'
MsgBox(0, $Number, _Convertor($Number))
MsgBox(0, '2144578788778.156', _Convertor('2144578788778.156'))
Func _Convertor($_number)
; 如果需要换算更大的数值, 请将其单位按顺序加入数组,并修改数组下标!!
Local $Place[5]=['', " Thousand ", " Million ", " Billion ", " Trillion "]
$_number= StringStripWS($_number, 8)
; 检测非法数值
If StringRegExp($_number, '[^\.,\d]|,,|\.\.|\d+\.\d+\.\d') Or StringRegExp($_number, '^\D|\D$') Then Return SetError(1)
Local $cents = '', $Result = ''
$_number = StringReplace($_number, ',', '')
If StringInStr($_number, '.') Then
$_number = Round($_number, 2)
$cents = StringLeft(StringRegExpReplace($_number, '\d+\.(\d+)', '\1') & '0', 2)
$cents = GetHundreds($cents) & ' Cents'
$_number = StringRegExpReplace($_number, '([^\.]+)\.\d+', '\1')
EndIf
Local $i = 0
While 1
$n = StringRight($_number, 3)
$Result = GetHundreds($n) & $Place[$i] & $Result
$_number = StringTrimRight($_number, 3)
If $_number = '' Then ExitLoop
$i += 1
WEnd
Return StringRegExpReplace($Result & ' ' & $cents, '\h+', ' ')
EndFunc
;以百位数 + 十位数 + 个位数: 100-999 转换成英文
Func GetHundreds($MyNumber)
Local $h, $t, $D
If Number($MyNumber) = 0 Then Return ''
$MyNumber = StringFormat('%03d', $MyNumber)
; 确定百位数的值
$h = StringLeft($MyNumber, 1)
If $h <> "0" Then
$h = GetDigit($h) & " Hundred "
Else
$h = ''
EndIf
; 十位数 及 个位数
$t = StringMid($MyNumber, 2, 1)
$d = StringRight($MyNumber, 1)
If $t = 1 Then
$t = GetTens(StringRight($MyNumber, 2))
ElseIf $t = 0 Then
$t = GetDigit($d)
Else
$t = GetTens(StringRight($MyNumber, 2)) & ' ' & GetDigit($d)
EndIf
Return $h & $t
EndFunc ;==>GetHundreds
; 转换十位的数字 10 到 90 成英文.
Func GetTens($TensText)
Local $Result
If StringLeft($TensText, 1) = 0 Then
Return ''
ElseIf StringLeft($TensText, 1) = 1 Then ; 10 ~ 19
Switch Number($TensText)
Case 10
Return "Ten"
Case 11
Return "Eleven"
Case 12
Return "Twelve"
Case 13
Return "Thirteen"
Case 14
Return "Fourteen"
Case 15
Return "Fifteen"
Case 16
Return "Sixteen"
Case 17
Return "Seventeen"
Case 18
Return "Eighteen"
Case 19
Return "Nineteen"
EndSwitch
Else ; 20~99
Switch Number(StringLeft($TensText, 1))
Case 2
Return "Twenty"
Case 3
Return "Thirty"
Case 4
Return "Forty"
Case 5
Return "Fifty"
Case 6
Return "Sixty"
Case 7
Return "Seventy"
Case 8
Return "Eighty"
Case 9
Return "Ninety"
EndSwitch
EndIf
EndFunc ;==>GetTens
; 个位的数字 1 to 9
Func GetDigit($Digit)
Switch $Digit
Case 1
Return "One"
Case 2
Return "Two"
Case 3
Return "Three"
Case 4
Return "Four"
Case 5
Return "Five"
Case 6
Return "Six"
Case 7
Return "Seven"
Case 8
Return "Eight"
Case 9
Return "Nine"
Case Else
Return ""
EndSwitch
EndFunc ;==>GetDigit
|