熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

用VB把數字轉成中文字符串

2022-06-13   來源: .NET編程 

  根據數字的讀法源碼天空寫了一個把數字轉成中文字符串的程序

  參數一為數字

  參數二為是不是反回人民幣大寫

  參數三為是不是直接讀數字否則帶有十百等單位

  參數四為設置小數點後面的位數默認為

  使用方法是

  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


From:http://tw.wingwit.com/Article/program/net/201311/12736.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.