分享
 
 
 

数字转英文(货币)大写

王朝c#·作者佚名  2006-12-17
窄屏简体版  字體: |||超大  

'功能模块:数字转英文(货币)大写

'Public Function NumberToString(Number As Double) As String

'调用形式:debug.print NumberToString(1234.32)

'说明:最大支持12位数字,小数点后精确两位

'程序:杨鑫光(Volitation)

Dim StrNO(19) As String

Dim Unit(8) As String

Dim StrTens(9) As String

Public Function NumberToString(Number As Double) As String

Dim Str As String, BeforePoint As String, AfterPoint As String, tmpStr As String

Dim Point As Integer

Dim nBit As Integer

Dim CurString As String

Call Init

'//开始处理

Str = CStr(Round(Number, 2))

' Str = Number

If InStr(1, Str, ".") = 0 Then

BeforePoint = Str

AfterPoint = ""

Else

BeforePoint = Left(Str, InStr(1, Str, ".") - 1)

AfterPoint = Right(Str, Len(Str) - InStr(1, Str, "."))

End If

If Len(BeforePoint) > 12 Then

NumberToString = "Too Big."

Exit Function

End If

Str = ""

Do While Len(BeforePoint) > 0

nNumLen = Len(BeforePoint)

If nNumLen Mod 3 = 0 Then

CurString = Left(BeforePoint, 3)

BeforePoint = Right(BeforePoint, nNumLen - 3)

Else

CurString = Left(BeforePoint, (nNumLen Mod 3))

BeforePoint = Right(BeforePoint, nNumLen - (nNumLen Mod 3))

End If

nBit = Len(BeforePoint) / 3

tmpStr = DecodeHundred(CurString)

If (BeforePoint = String(Len(BeforePoint), "0") Or nBit = 0) And Len(CurString) = 3 Then

If CInt(Left(CurString, 1)) <> 0 And CInt(Right(CurString, 2)) <> 0 Then

tmpStr = Left(tmpStr, InStr(1, tmpStr, Unit(4)) + Len(Unit(4))) & Unit(8) & " " & Right(tmpStr, Len(tmpStr) - (InStr(1, tmpStr, Unit(4)) + Len(Unit(4))))

Else 'If CInt(Left(CurString, 1)) <> 0 And CInt(Right(CurString, 2)) = 0 Then

tmpStr = Unit(8) & " " & tmpStr

End If

End If

If nBit = 0 Then

Str = Trim(Str & " " & tmpStr)

Else

Str = Trim(Str & " " & tmpStr & " " & Unit(nBit))

End If

If Left(Str, 3) = Unit(8) Then Str = Trim(Right(Str, Len(Str) - 3))

If BeforePoint = String(Len(BeforePoint), "0") Then Exit Do

'Debug.Print Str

Loop

BeforePoint = Str

If Len(AfterPoint) > 0 Then

AfterPoint = Unit(6) & " " & DecodeHundred(AfterPoint) & " " & Unit(7)

Else

AfterPoint = Unit(5)

End If

NumberToString = BeforePoint & " " & AfterPoint

End Function

Private Function DecodeHundred(HundredString As String) As String

Dim tmp As Integer

If Len(HundredString) > 0 And Len(HundredString) <= 3 Then

Select Case Len(HundredString)

Case 1

tmp = CInt(HundredString)

If tmp <> 0 Then DecodeHundred = StrNO(tmp)

Case 2

tmp = CInt(HundredString)

If tmp <> 0 Then

If (tmp < 20) Then

DecodeHundred = StrNO(tmp)

Else

If CInt(Right(HundredString, 1)) = 0 Then

DecodeHundred = StrTens(Int(tmp / 10))

Else

DecodeHundred = StrTens(Int(tmp / 10)) & "-" & StrNO(CInt(Right(HundredString, 1)))

End If

End If

End If

Case 3

If CInt(Left(HundredString, 1)) <> 0 Then

DecodeHundred = StrNO(CInt(Left(HundredString, 1))) & " " & Unit(4) & " " & DecodeHundred(Right(HundredString, 2))

Else

DecodeHundred = DecodeHundred(Right(HundredString, 2))

End If

Case Else

End Select

End If

End Function

Private Sub Init()

If StrNO(1) <> "One" Then

StrNO(1) = "One"

StrNO(2) = "Two"

StrNO(3) = "Three"

StrNO(4) = "Four"

StrNO(5) = "Five"

StrNO(6) = "Six"

StrNO(7) = "Seven"

StrNO(8) = "Eight"

StrNO(9) = "Nine"

StrNO(10) = "Ten"

StrNO(11) = "Eleven"

StrNO(12) = "Twelve"

StrNO(13) = "Thirteen"

StrNO(14) = "Fourteen"

StrNO(15) = "Fifteen"

StrNO(16) = "Sixteen"

StrNO(17) = "Seventeen"

StrNO(18) = "Eighteen"

StrNO(19) = "Nineteen"

StrTens(1) = "Ten"

StrTens(2) = "Twenty"

StrTens(3) = "Thirty"

StrTens(4) = "Forty"

StrTens(5) = "Fifty"

StrTens(6) = "Sixty"

StrTens(7) = "Seventy"

StrTens(8) = "Eighty"

StrTens(9) = "Ninety"

Unit(1) = "Thousand" '第一个三位

Unit(2) = "Million" '第二个三位

Unit(3) = "Billion" '第三个三位

Unit(4) = "Hundred"

Unit(5) = "Only"

Unit(6) = "Point"

Unit(7) = "Cent"'不是货币的话,把此值赋空

Unit(8) = "And"

End If

End Sub

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有