日期:2009-07-24  浏览次数:20964 次


常有人问及钱或数字串要如何转换为中文?由于转过来是一个比较麻烦的事情。本人耐着性子把它搞定。

现将本人测试时的程序代码贴上,我是将它们转换为大写的中文,希望大家用时方便一些。当然这是比较烦的了,不


要紧,慢慢看。呵呵......

代码如下:

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<script language=vbscript>
<!--
dim aa,bb
function do_change(typeid)
Dim wordarr(11), unitarr1(4), unitarr2(4), unitarr3(3)
Dim int1 ' 整数部份
Dim point1 ' 小数部份
Dim int1_str ' 整数部份
Dim point1_str ' 小数部份
Dim str1, len1, i,j
Dim idx1, idx2,idx3, unit_tag

aa=testm.text1.value
If Not IsNumeric(aa) Then ' check error
msgbox "input is no number"
Exit Function
End If
if typeid = "money" then
str1 = FormatNumber(aa, 2, -1, 0)
else
str1 = FormatNumber(aa, 20, -1, 0)
end if
str1 = Replace(str1, ",", "")
len1 = Len(str1)

wordarr(1) = "零"
wordarr(2) = "壹"
wordarr(3) = "贰"
wordarr(4) = "参"
wordarr(5) = "肆"
wordarr(6) = "伍"
wordarr(7) = "陆"
wordarr(8) = "柒"
wordarr(9) = "捌"
wordarr(10) = "玖"
unitarr1(1) = "拾"
unitarr1(2) = "佰"
unitarr1(3) = "仟"
unitarr2(1) = "万"
unitarr2(2) = "亿"
unitarr2(3) = "兆"
unitarr3(1) = "角"
unitarr3(2) = "分"

j = 0
For i = 1 To len1
If mid(str1,i,1) = "." Then '将数字分成整数部分,及小数部分
j = i
Exit For
End If
Next
If j <> 0 Then
int1 = Mid(str1, 1, j - 1)
point1 = Mid(str1, j + 1, len1)
Else
int1 = str1
point1 = Null
End If

len1 = Len(int1)
If len1 = 0 Or int1 = "0" Then
int1_str = "零"
Else
j = 0
For i = len1 To 1 Step -1
j = j + 1
idx1 = mid(int1,j,1)
idx2 = (i - 1) / 4
idx3 = (i - 1) Mod 4
If idx3 = 0 Then
If idx1 <> 0 Then
int1_str = RTrim(int1_str) & wordarr(idx1 + 1)
unit_tag = "n"
End If
If idx2 <> 0 Then
If unit_tag <> "y" Then
int1_str = RTrim(int1_str) & unitarr2(idx2)
unit_tag = "y"
End If
End If
Else
If idx1 <> 0 Then
int1_str = RTrim(int1_str) & wordarr(idx1 + 1) & unitarr1(idx3)
unit_tag = "n"
Else
If int1(j + 1) <> 0 Then
int1_str = RTrim(int1_str) & wordarr(1)
unit_tag = "n"
End If
End If
End If
Next
End If

len1 = Len(point1)
If len1 = 0 Or point1 = "00" Then
point1_str = "零"
Else
If typeid = "money" Then
If mid(point1,1,1) = "0" Then
point1_str = "零"
End If
For p_1 = 1 To len1
idx1 = mid(point1,p_1,1)
If