刚写了段转换金额的代码,大家看看

qixiao 2004-11-09 08:31:30
欢迎指教!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim str As String
str = Me.TextBox1.Text.Trim
Dim isfs As Boolean
If Left(str, 1) = "-" Then
isfs = True
str = str.Remove(0, 1)
Else
isfs = False
End If
Dim strpoint As String
Dim point() As String
Dim j As Int16
Dim jj() As String
Dim jjj As String
jjj = ""
If str.IndexOf(".") <> -1 Then
point = Split(str, ".", -1, CompareMethod.Text)
str = point(0)
strpoint = point(1)
ReDim jj(strpoint.Length - 1)
For j = 0 To strpoint.Length - 1
jj(j) = Left(strpoint, 1)
strpoint = Right(strpoint, strpoint.Length - 1)
jjj = jjj + convert(jj(j))
Next
End If
Dim strcode As String
strcode = ""
While strcode.Length <= str.Length
strcode = strcode & "2345" & "2346"
End While
strcode = "1" & strcode
strcode = Left(strcode, str.Length)
Dim i As Int16
Dim a() As String
Dim strcode1 As String
Dim countstr As Int16
Dim strcode2 As String
countstr = strcode.Length
ReDim a(strcode.Length - 1)
For i = 0 To countstr - 1
a(i) = Right(strcode, 1)
strcode = Left(strcode, strcode.Length - 1)
strcode1 = strcode1 & a(i)
strcode2 = strcode2 & "," & Mid(str, i + 1, 1) & Mid(strcode1, i + 1, 1)
Next
strcode2 = Right(strcode2, strcode2.Length - 1)
Dim newstr() As String
newstr = Split(strcode2, ",", -1, CompareMethod.Text)
Dim ii As Int16
Dim laststr As String
Dim strcode3 As String
Dim leftstr As String
Dim rightstr As String
For ii = 0 To newstr.Length - 1
strcode3 = newstr(ii)
leftstr = Left(strcode3, 1)
rightstr = Right(strcode3, 1)
rightstr = Replace(rightstr, rightstr, convert2(rightstr))
leftstr = Replace(leftstr, leftstr, convert(leftstr))
If leftstr = "零" And (rightstr = "拾" Or rightstr = "佰" Or rightstr = "仟") Then
rightstr = ""
End If
If leftstr = "零" And (rightstr = "万" Or rightstr = "亿") Then
leftstr = ""
End If
strcode3 = leftstr & rightstr
laststr = laststr & strcode3
Next
While laststr.IndexOf("佰零万") <> -1
laststr = laststr.Replace("零万", "万")
End While
While laststr.IndexOf("仟零零万") <> -1
laststr = laststr.Replace("零零万", "万")
End While
While laststr.IndexOf("零万") <> -1
laststr = laststr.Replace("零万", "零")
End While
While laststr.IndexOf("零亿") <> -1
laststr = laststr.Replace("零亿", "亿")
End While
While laststr.IndexOf("零零") <> -1
laststr = laststr.Replace("零零", "零")
End While
While Right(laststr, 1) = "零"
laststr = Left(laststr, laststr.Length - 1)
End While
If isfs = True Then
laststr = "负" & laststr
End If
If jjj = "" Then
TD2.InnerHtml = laststr
Else
If laststr = "" Then
TD2.InnerHtml = "零点" & jjj
Else
TD2.InnerHtml = laststr & "点" & jjj
End If
End If

End Sub

Function convert(ByVal num As String)
Select Case num
Case "1"
convert = "壹"
Case "2"
convert = "贰"
Case "3"
convert = "叁"
Case "4"
convert = "肆"
Case "5"
convert = "伍"
Case "6"
convert = "陆"
Case "7"
convert = "柒"
Case "8"
convert = "捌"
Case "9"
convert = "玖"
Case "0"
convert = "零"
End Select
End Function

Function convert2(ByVal num As String)
Select Case num
Case "1"
convert2 = ""
Case "2"
convert2 = "拾"
Case "3"
convert2 = "佰"
Case "4"
convert2 = "仟"
Case "5"
convert2 = "万"
Case "6"
convert2 = "亿"
End Select
End Function
...全文
161 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunzhemei 2004-11-25
  • 打赏
  • 举报
回复
比偶强了点,不要伤心难过 再接再厉啊

来接分的。
@_@~~~
qixiao 2004-11-25
  • 打赏
  • 举报
回复
失败
结了!
chuanzai 2004-11-14
  • 打赏
  • 举报
回复
来接分的。。。嘿嘿
simonzone 2004-11-14
  • 打赏
  • 举报
回复
嘻嘻
qixiao 2004-11-14
  • 打赏
  • 举报
回复
看来写的是差极了,郁闷!
:(
qixiao 2004-11-11
  • 打赏
  • 举报
回复
为什么这么说?
我不知道跟asp有什么关系
这段代码到winform下稍加修改一样可以运行的
johnsunac 2004-11-11
  • 打赏
  • 举报
回复
这样的代码感觉就是asp的翻版
minghui000 2004-11-10
  • 打赏
  • 举报
回复
帮你up一下

+

留个位置学习

+

接分
minghui000 2004-11-10
  • 打赏
  • 举报
回复
不用麻烦复杂吧!
qixiao 2004-11-09
  • 打赏
  • 举报
回复
代码有点糙:)

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧