如何实现人民币的大写转换?_编程10000问

第一个办法,这个程序可以进行万亿以下的货币金额转换(够用的了吧),其中汉字与数字均按一位计:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Function AtoC(a As Currency) As String
     ' 定义两个字符串,A的值最多是两位小数.
    Dim String1 As String 

' 如下定义.
    Dim String2 As String 

' 如下定义.
    Dim String3 As String 

' 从原A值中取出的值.
    Dim I As Integer       

 ' 循环变量.

    Dim J As Integer       

' A的值乘以100的字符串长度.
    Dim Ch1 As String     

' 数字的汉语读法.
    Dim Ch2 As String     

' 数字位的汉字读法.
    Dim nZero As Integer   

' 用来计算连续的非零数是几个.

    String1 = "零壹贰叁肆伍陆柒捌玖"
    String2 = "万仟佰拾亿仟佰拾万仟佰拾元角分"
    'MsgBox CStr(a * 100)
    If InStr(1, CStr(a * 100), ".") <> 0 Then
        err.Raise 5000, , "该函数( AtoC() )只转换两位小数以内的数值!"
    End If

    J = Len(CStr(a * 100))
    String2 = Right(String2, J)       

' 取出对应位数的StrING2的值.

    For I = 1 To J
        String3 = Mid(a * 100, I, 1)   

' 取出需转换的某一位的值.
        If String3 <> "0" Then
            Ch1 = Mid(String1, Val(String3) + 1, 1)
            Ch2 = Mid(String2, I, 1)
            nZero = nZero + 1         

' 表示本位不为零.
        Else
            If nZero <> 0 Or I = J - 9 Or I = J - 5 Or I = J - 1 Then
                If Right(AtoC, 1) = "零" Then AtoC = Left(AtoC, Len(AtoC) - 1)
                Ch1 = "零"
            Else
                Ch1 = ""
            End If
                                  

If I = J - 10 Then

' 如果转换的数值需要扩大,则要改动以下表达式 I 的值.
                Ch2 = "亿"
            ElseIf I = J - 6 Then
                If nZero <> 0 Then
                    Ch2 = "万"
'                    nZero = 0
                End If
            ElseIf I = J - 2 Then
                Ch2 = "元"
            ElseIf I = J Then
                Ch2 = "整"
            Else
                Ch2 = ""
            End If
            nZero = 0
        End If

        AtoC = AtoC & Ch1 & Ch2
    Next I

        AtoC = Replace(AtoC, "零元", "元")
        AtoC = Replace(AtoC, "零万", "万")
        AtoC = Replace(AtoC, "零亿", "亿")
        AtoC = Replace(AtoC, "零整", "整")
       ' 以上将多余的零去掉

End Function

 

第二个办法:照下面写就成了!

<%
dim str(9)
str(0)="零"
str(1)="壹"
str(2)="贰"
str(3)="叁"
str(4)="肆"
str(5)="伍"
str(6)="陆"
str(7)="柒"
str(8)="捌"
str(9)="玖"
aa=Request.form("source")
hh=formatnumber(aa,2,-1)
aa=replace(hh,".","")
aa=replace(aa,",","")
for i=1 to len(aa)
    s=mid(aa,i,1)
  mynum=str(s)
  select case(len(aa)+1-i)
    case 1: k= mynum&"分"
    case 2: k= mynum&"角"
    case 3: k= mynum&"元"
    case 4: k= mynum&"拾"
    case 5: k= mynum&"佰"
    case 6: k= mynum&"仟"
    case 7: k= mynum&"万"
    case 8: k= mynum&"拾"
    case 9: k= mynum&"佰"
    case 10: k= mynum&"仟"
  end select
    m=m&k
next
%>

<html>
<head>
<title>精彩春风之数字大小写转换</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<!--
Elseif(s=".") then
    n=m
    i=i+2
    for j=i to len(aa)
      s=mid(aa,i,1)
        mynum=str(s)
      select case(len(aa)+1-i)
      case 1: p= mynum&"分"
      case 2: p= mynum&"角"
      end select
      m=m&p
    next
-->

<body>
<form method="post"  name="forma">
  <input type="text" name="source" value="<%=hh%>">
  =
  <input type="text" name="result" value="<%=m%>" size="40">

<input type="submit" name="Submit" value="开始转换" >
</form>
</body></html>

 

时间: 2024-07-29 05:23:09

如何实现人民币的大写转换?_编程10000问的相关文章

如何把Recordset转换成彩色的XML文件_编程10000问

<%@ codepage="65001" %> <!-- #INCLUDE FILE="ADOVBS.INC" --> <% Response.ContentType = "text/xml" ' 如果不在 adovbs.inc 里,则设置一个常量.  <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office&qu

如何用ASP输出HTML文件?_编程10000问

<!--#include file="top.inc"--><%u_title=request.form("u_title")<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> ' 检查标题是否被输入.if u_title = "" then%><form method="P

ASP问答集_编程10000问

问:为什么我的记录集的RecordCount值总是返回-1? 答:你应当使用这种模式来打开存取数据库的记录集:   rec.open strSQL,conn,1,1   其中的strSQL是操作数据库的SQL语句;conn是联接数据库的Connection 变量. 问:我在ASP脚本中写了很多的注释,这会不会影响服务器处理ASP文件的速度? 答:经国外技术人员测试,带有过多注释的ASP文件整体性能仅仅会下降0.1%,也就是说基本上不会影响到服务器的性能下降的. 问:我需不需要在每个ASP文件的开

如何创建Word文件?_编程10000问

creatdoc.asp<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> <!DOCTYPE html PUBLIC "-//W3C/Dtd html 3.2 Final//EN"><head><title>星河影动之创建Word文件</title><META HTTP-EQUIV="Re

如何动态添加Form项?_编程10000问

<%@ language = vbscript%><% Response.Expires = 0 %><html><head><title>星河影动之动态添加Form项</title></head><body><%If Request("Action") = "提交列表" ThenResponse.Write "<B>提交的项:</B&g

如何把URL和邮件地址转换为超级链接?_编程10000问

Function InsertHyperlinks(inText)Dim objRegExp, strBufDim objMatches, objMatchDim Value, ReplaceValue, iStart, iEnd   strBuf = ""  iStart = 1  iEnd = 1  Set objRegExp = New RegExp   objRegExp.Pattern = "\b(www|http|\S+@)\S+\b"  <?xm

如何取回已忘记的密码?_编程10000问

forget.asp<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> ' 申请. <html> <head> <title>闪亮日子之用户密码核实</title> </head> <div align="center"><center> <table border

如何制作一个防止多次刷新计数的图片计数器?_编程10000问

请问如何做一个专业的图片计数器? <% countlong=8     ' 定义计数器位数. On Error Resume Next     ' 忽略所有的错误. count=server.mappath(count.txt) set cou = server.createobject(scripting.filesystemobject) set out=cou.opentextfile(count,1,false,false) counter=out.readline out.close

网上考试设计思路是怎样的?_编程10000问

global.asa < script LANGUAGE=VBScript RUNAT=Server > Sub Application_OnStart    dbPath = "DBQ=" & Server.Mappath("onlinetest.mdb")    dbConnectionString =  "DRIVER={Microsoft Access Driver (*.mdb)}; " & dbPath