我的一亩三分地 我就喜欢!
13fen  设为主页
 收藏本站
 
当前位置: > 一亩三分地:首页 > 网络学院 > 网络编程 > ASP专区 > Asp组件/脚本 > 数字字串(钱)转换为中文(大写)
热门文章排行
热门文章排行 手推车”功能的实现(10-07)
八大法则防范ASP网站漏洞(10-23)
ASP教程十一、调试ASP脚本(10-23)
在JSP中访问数据库大全(10-23)
虚机服务中常见Asp.Net低级错误一览(03-21)
精采文章排行
精采文章排行 ASP.NET实现抓取网页中的链接(11-15)
ASP连接数据库的11种方法(11-10)
如何动态创建网页的RSS内容摘要(11-10)
ASP网站漏洞及入侵防范方法(11-10)
ASP自定义函数:对字符串正则替换(11-10)
技术专题推荐
网管论坛交流
 

数字字串(钱)转换为中文(大写) 

作者:佚名   来源:一亩三分地   点击:   日期:2007-03-28

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

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

代码如下:

<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 idx1 <> 0 Then
point1_str = RTrim(point1_str) & wordarr(idx1 + 1) & unitarr3(p_1)
End If
Next
else
For p_1 = len1 To 1 step -1
idx1 = mid(point1,p_1,1)
If idx1 <> 0 Then
point1_str = wordarr(idx1 + 1) & RTrim(point1_str)
end if
next
End If
End If

If typeid = "money" Then
If int1_str <> "零" Or j = 0 Then
bb = RTrim(int1_str) & "元"
End If
If point1_str <> "零" Then
bb = RTrim(bb) & RTrim(point1_str) & "整"
Else
bb = RTrim(bb) & "整"
End If
Else
bb = RTrim(int1_str)
If point1_str <> "零" and trim(point1_str) <>"" Then
bb = RTrim(bb) & "点" & RTrim(point1_str)
End If
End If
testm.text2.value = bb
End Function
-->
</script>
</HEAD>
<BODY>
<form method="post" name="testm" id="testm" action="testm.asp">
<P><INPUT id=text1 name=text1><br>
<INPUT id=button1 name=button1 type=button value="money" onclick="do_change('money')">
<INPUT id=button2 name=button2 type=button value="normal" onclick="do_change('normal')"><br>
<INPUT id=text2 name=text2 style="HEIGHT: 22px; WIDTH: 447px"></P>
</form>
</BODY>
</HTML>

当然, 那位若有更好更简便的方法, 可别忘了也告诉我一下, 让我也进步进步。 fz_chenjl@163.net

OK !?!?



文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【论坛讨论

   相关文章:
·ASP中巧用Response属性 ·第六课:ASP脚本循环语句
·在 Web 页上使用条件数值格式 ·连接数据库查询手册(不仅仅适用于asp)
·警惕"给你的FileSystemObject对象加把锁" ·用ASP做全文检索

   文章评论:(条)
  
 请留名: 匿名评论   点击查看所有评论 网管论坛
 

  责任编辑:一分  声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。