asp如何实现人民币的大写转换?
发布时间:2010-05-24 18:27:00
具体代码和实现方法见下:
第一个办法,这个程序可以进行万亿以下的货币金额转换(够用的了吧),其中汉字与数字均按一位计:
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>asp之家 - 数字大小写转换 -aspxhome.com</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 bgcolor="#FFFFFF">
<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>
猜你喜欢
- 1. 如何停止任务?我们可以通过 asyncio.Task 对象上的 cancel() 方法取消任务。如果任务被取消,cancel() 方法
- 目录:分析和设计组件编码实现和算法用 Ant 构建组件测试 JavaScript 组件我们走到哪儿了?前两期思考了太多东西,你是否已有倦意?
- 引言context包比较小,是阅读源码比较理想的一个入手,并且里面也涵盖了许多go设计理念可以学习。go的Context作为go并发方式的一
- 如下所示:# -*- coding:utf-8 -*-import xlrdimport sysimport reimport jsondi
- 前言首先,一个常见的问题是,ECMAScript 和 JavaScript 到底是什么关系?ECMAScript是一个国际通过的标准化脚本语
- Scala 循环有的时候,我们可能需要多次执行同一块代码。一般情况下,语句是按顺序执行的:函数中的第一个语句先执行,接着是第二个语句,依此类
- 如下所示:import cv2import os#图片路径im_dir = '/home/suanfa/data/out/20170
- 本文实例讲述了python中xrange用法。分享给大家供大家参考。具体如下:先来看如下示例:>>> x=xrange(0
- 长期以来我就有对几年来交互设计的心得进行总结整理的想法。回到中国来亲身体会到不少同行,主要是交互设计师和视觉设计师对于交互设计的困惑,以及其
- 如果你有个5、6 G 大小的文件,想把文件内容读出来做一些处理然后存到另外的文件去,你会使用什么进行处理呢?不用在线等,给几个错误示范:有人
- 如何判断年份是否为闰年闰年:所谓闰年即能被4整除,但不能被100整除的年份,或者能被400整除的年份。def Year():
- 在一个大型数据库中,数据的更改是非常频繁的。 而建立在这些数据上的索引也是需要经常去维护的。 否则这这些数据索引就起不到起应起的作用。甚至会
- 在python中常看到在定义函数是使用@func. 这就是装饰器, 装饰器是把一个函数作为参数的函数,常常用于扩展已有函数,即不改变当前函数
- 本文实例讲述了Python利用正则表达式匹配并截取指定子串及去重的方法。分享给大家供大家参考。具体如下:import repattern=r
- 问题:数据库实际大小为600MB, 日志文件实际大小为33MB, 但日志文件占用空间为2.8GB!试了多种方式,SHIRNK DATABAS
- 有一个需求是要在一个云监控的状态值中存储多个状态(包括可同时存在的各种异常、警告状态)使用了位运算机制在一个int型中存储。现在监控日志数据
- 前言最近经历了一次服务器SQL SERVER 数据库服务器端事务日志爆满,导致服务器数据库写入不进数据的宕机事件,经过此次事件的发生,奉劝各
- 概述在使用Typora写比较长的文章时,需要给章节编号,方便区分层次。如果手动编号,一旦章节顺序改变,很多章节的编号都需要一一手动修改,极其
- 如下所示:import pandas as pdpath='F:/python/python数据分析与挖掘实战/图书配套数据、代码/
- EcmaScript正則表達式( 深入淺出系列之淺出 ^_^ )在线正则表达式测试:http://www.aspxhome.com/RegE