请选择 进入手机版 | 继续访问电脑版
查看: 180|回复: 0

[.NET开发] VB.NET 人民币大小写(正负)的代码

3万

主题

3万

帖子

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
100197
发表于 2015-11-23 17:52:07
<无详细内容>
  1. Sub ChangeSize_Selected(ByVal sender As Object, ByVal e As EventArgs)
  2. panel1.Width = papersize.SelectedValue
  3. End Sub
  4. Function ConvertToRMB(ByVal inputString As String) As String
  5. Dim numList As String = “零壹贰叁肆伍陆柒捌玖”
  6. Dim rmbList As String = “分角元拾佰仟万拾佰仟亿拾佰仟万”
  7. Dim number As Double = 0
  8. Dim tempOutString As String = “”
  9. Try
  10. number = Double.Parse(inputString)
  11. Catch ex As SystemException
  12. ClientScript.RegisterStartupScript(Me.GetType(), “”, GetAlertInfo(“传入参数非数字!”))
  13. ‘ MessageBox.Show(“”)
  14. End Try
  15. If number > 9999999999999.99 Then
  16. Return “超出范围的人民币值”
  17. End If
  18. Dim tempNumberString As String = Convert.ToInt64( number * 100).ToString()
  19. Dim tempNmberLength As Integer = tempNumberString.Length
  20. Dim i As Integer = 0
  21. If tempNumberString.StartsWith(“-”) Then
  22. tempOutString = “负”
  23. i = i + 1
  24. end if
  25. While i < tempNmberLength
  26. Dim oneNumber As Integer = Int32.Parse(tempNumberString.Substring(i, 1))
  27. Dim oneNumberChar As String = numList.Substring(oneNumber, 1)
  28. Dim oneNumberUnit As String = rmbList.Substring(tempNmberLength – i – 1, 1)
  29. If Not (oneNumberChar = “零”) Then
  30. tempOutString += oneNumberChar + oneNumberUnit
  31. Else
  32. If oneNumberUnit = “亿” OrElse oneNumberUnit = “万” OrElse oneNumberUnit = “元” OrElse oneNumberUnit = “零” Then
  33. While tempOutString.EndsWith(“零”)
  34. tempOutString = tempOutString.Substring(0, tempOutString.Length – 1)
  35. End While
  36. End If
  37. If oneNumberUnit = “亿” OrElse (oneNumberUnit = “万” AndAlso Not tempOutString.EndsWith(“亿”)) OrElse oneNumberUnit = “元” Then
  38. tempOutString += oneNumberUnit
  39. Else
  40. If Not tempOutString Is Nothing Then
  41. Dim tempEnd As Boolean = tempOutString.EndsWith(“亿”)
  42. Dim zeroEnd As Boolean = tempOutString.EndsWith(“零”)
  43. If tempOutString.Length > 1 Then
  44. Dim zeroStart As Boolean = tempOutString.Substring(tempOutString.Length – 2, 2).StartsWith(“零”)
  45. If Not zeroEnd AndAlso (zeroStart OrElse Not tempEnd) Then
  46. tempOutString += oneNumberChar
  47. End If
  48. Else
  49. If Not zeroEnd AndAlso Not tempEnd Then
  50. tempOutString += oneNumberChar
  51. End If
  52. End If
  53. End If
  54. End If
  55. End If
  56. i += 1
  57. End While
  58. If Not tempOutString Is Nothing Then
  59. While tempOutString.EndsWith(“零”)
  60. tempOutString = tempOutString.Substring(0, tempOutString.Length – 1)
  61. End While
  62. While tempOutString.EndsWith(“元”)
  63. tempOutString = tempOutString + “整”
  64. End While
  65. Return tempOutString
  66. Else
  67. Return “”
  68. End If
  69. End Function
复制代码



上一篇:QB黑白棋
下一篇:VB: 在 GDI+ 上划线
回复

使用道具 举报