4月162015
阿拉伯数字转换成中文大写数字
原创作者ACN站:3mile
如:550065转换成“五十五万零六十五”或“伍拾伍万零陆拾伍”
可作为UDF使用的。
NUM2CWORD($number,$vValue="")参数为0则只是大写,参数为1为古体
#include <array.au3> Dim $numb = InputBox("", "") $go = NUM2CWORD($numb) $go1 = NUM2CWORD($numb, 1) MsgBox(0, 0, "原始数字:" & $numb & @CRLF & "中文大写:" & $go & @CRLF & "中文古写:" & $go1) Func NUM2CWORD($number, $vValue = "") If Not IsNumber(Execute($number)) Then Return SetError(1, 0, "");如果输入的不是数字返回错误代码1 If $number > 999999999999 Then Return SetError(2, 0, "");如果大于千亿返回错误代码2 If $vValue < 0 Or $vValue = "" Then $vValue = 0 If $vValue = 1 Then Dim $Cnum[10] = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"] Dim $Cwei[12] = ["", "拾", "佰", "仟", "万", "拾万", "佰万", "仟万", "亿", "拾亿", "佰亿", "仟亿"] Else Dim $Cnum[10] = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"] Dim $Cwei[12] = ["", "十", "百", "千", "万", "十万", "百万", "千万", "亿", "十亿", "百亿", "千亿"] EndIf Local $str, $xiao If StringRegExp($number, '\d+\.\d+', 0) Then;判断是否有小数 $number_temp = StringRegExp($number, '(\d+)\.(\d+)', 3) $number = $number_temp[0] $number_xiao = $number_temp[1] $number_xiao_wei = StringLen($number_xiao) Else $number_xiao_wei = 0 EndIf $number_wei = StringLen($number) If $number_xiao_wei > 0 Then;计算小数部分 For $x = 1 To $number_xiao_wei $xiao &= $Cnum[StringMid($number_xiao, $x, 1)] Next EndIf $n = $number_wei For $i = 1 To $number_wei;计算整数部分 If StringMid($number, $i, 1) = 0 Then If StringMid($number, $i - 1, 1) = 0 Then $n -= 1 Else $str &= $Cnum[0] $n -= 1 EndIf Else $str &= $Cnum[StringMid($number, $i, 1)] & $Cwei[$n - 1] $n -= 1 EndIf Next $wan = StringRegExp($str, '万', 3) $yi = StringRegExp($str, '亿', 3) If UBound($wan) > 1 Then $str = StringReplace($str, "万", "", UBound($wan) - 1) If UBound($yi) > 1 Then $str = StringReplace($str, "亿", "", UBound($yi) - 1) If StringRight($str, 1) = "零" Then $str = StringMid($str, 1, StringLen($str) - 1) If StringLen($xiao) > 0 Then If StringLen($str) > 0 Then $str = $str & "点" & $xiao Else $str = "零点" & $xiao EndIf EndIf Return $str EndFunc ;==>NUM2CWORD```
本文固定链接: http://jianyiit.com/post-94.html
扫描二维码,在手机上阅读
发表评论
木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!