电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

用VB把数字转成中文字符串


发布日期:2023/10/15
 

根据数字的读法源码天空写了一个把数字转成中文字符串的程序

参数一为数字

参数二为是不是反回人民币大写

参数三为是不是直接读数字否则带有十百等单位

参数四为设置小数点后面的位数默认为

使用方法是

t=GetChinaNum( 返回 二千零五点零零零四三六

t=GetChinaNum( True 返回贰仟零伍元肆角肆分

t=GetChinaNum( True 返加二零零五点四三六

下面是程序代码

Function GetChinaNum(otherNum As Double Optional isRMB As Boolean Optional numOption As Boolean Optional dotNum As Integer) As String

On Error Resume Next

num = Trim(Str(Int(otherNum)))

If isRMB Then

numwei = 拾佰仟万拾佰仟亿拾佰仟

numshu = 零壹贰三肆伍陆柒捌玖拾

Else

numwei = 十百千万十百千亿十百千

numshu = 零一二三四五六七八九十

End If

If otherNum < And otherNum >= Then

num = Right(num

GetChinaNum = Left(numwei

End If

For i = To Len(num)

bstr = Mid(num i

If numOption Then

GetChinaNum = GetChinaNum + Mid(numshu Val(bstr) +

Else

GetChinaNum = GetChinaNum + Mid(numshu Val(bstr) +

If bstr = Then

If Mid(numwei Len(num) i ) = Or Mid(numwei Len(num) i ) = 亿 Then

Do While Right(GetChinaNum ) =

GetChinaNum = Left(GetChinaNum Len(GetChinaNum)

Loop

GetChinaNum = GetChinaNum + Mid(numwei Len(num) i

End If

Else

GetChinaNum = GetChinaNum + Mid(numwei Len(num) i

End If

GetChinaNum = Replace(GetChinaNum 零零

End If

Next i

If numOption = False Then

Do While Right(GetChinaNum ) =

GetChinaNum = Left(GetChinaNum Len(GetChinaNum)

Loop

End If

If isRMB Then

numrmb = 元角分

GetChinaNum = GetChinaNum + Mid(numrmb

If Val(num) <> otherNum Then

num = Trim(Str(Round(otherNum Val(num) )))

For i = To Len(num)

bstr = Mid(num i

GetChinaNum = GetChinaNum + Mid(numshu Val(bstr) + ) + Mid(numrmb i

Next i

Else

GetChinaNum = GetChinaNum +

End If

Else

If Val(num) <> otherNum Then

If dotNum = Then dotNum =

num = Trim(CStr(Round(otherNum Val(num) dotNum)))

If GetChinaNum = Then GetChinaNum =

GetChinaNum = GetChinaNum +

For i = To Len(num)

bstr = Mid(num i

GetChinaNum = GetChinaNum + Mid(numshu Val(bstr) +

Next i

End If

End If

End Function

上一篇:LINQ语句检查空对象的问题

下一篇:Global.asax使用介绍