当前位置: 首页 > 图文教程 > 网络编程 > ASP > 金额阿拉伯数字转换为中文的存储过程

ASP
asp中利用数组实现数据库记录的批量录入方法
vbs(asp)的栈类
加密處理使密碼更安全[CFS編碼加密]
在asp中通过vbs类实现rsa加密与解密
披著羊皮的大野狼 - Session
简体中文编码对应器
len(),lift(),right()不能正常识别中文的解决方法
实现WEB中的@虚拟域名系统(原理篇)
巧用ASP生成PDF文件
二级域名原理以及程序,申请即可开通
无组件上传图片到数据库中,最完整解决方案
在ASP中使用SQL语句之1:SELECT 语句
在ASP中使用SQL语句之2:用WHERE子句设置查询条件
在ASP中使用SQL语句之3:LIKE、NOT LIKE和 BETWEEN
在ASP中使用SQL语句之4:联合语句
在ASP中使用SQL语句之5:开始执行
在ASP中使用SQL语句之6:存储查询
在ASP中使用SQL语句之7:ORDER BY
在ASP中使用SQL语句之8:随机数
在ASP中使用SQL语句之9:表单操作

ASP 中的 金额阿拉伯数字转换为中文的存储过程


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 32 ::
收藏到网摘: n/a

Create Procedure AtoC
@ChangeMoney Money
as
Set Nocount ON
Declare @String1 char(20)
Declare @String2 char(30)
Declare @String4 Varchar(100)
Declare @String3 Varchar(100) --从原A值中取出的值
Declare @i int --循环变量
Declare @J Int --A的值乘以100的字符串长度
Declare @Ch1 Varchar(100) --数字的汉语读法
Declare @Ch2 Varchar(100) --数字位的汉字读法
Declare @Zero Int --用来计算连续有几个零
Declare @ReturnValue VarChar(100)

Select @ReturnValue = ''
Select @String1 = '零壹贰叁肆伍陆柒捌玖'
Select @String2 = '万仟佰拾亿仟佰拾万仟佰拾元角分'

Select @String4 = Cast(@ChangeMoney*100 as int)

select @J=len(cast((@ChangeMoney*100) as int))

Select @String2=Right(@String2,@J)

Select @i = 1

while @i<= @j Begin

Select @String3 = Substring(@String4,@i,1)

if @String3<>'0' Begin

Select @Ch1 = Substring(@String1, Cast(@String3 as Int) + 1, 1)
Select @Ch2 = Substring(@String2, @i, 1)
Select @Zero = 0 --表示本位不为零
end
else Begin
If (@Zero = 0) Or (@i = @J - 9) Or (@i = @J - 5) Or (@i = @J - 1)
Select @Ch1 = '零'
Else
Select @Ch1 = ''

Select @Zero = @Zero + 1 --表示本位为0

--如果转换的数值需要扩大,那么需改动以下表达式 I 的值。
Select Ch2 = ''

If @i = @J - 10 Begin
Select @Ch2 = '亿'
Select @Zero = 0
end

If @i = @J - 6 Begin
Select @Ch2 = '万'
Select @Zero = 0
end

if @i = @J - 2 Begin
Select @Ch2 = '元'
Select @Zero = 0
end

If @i = @J
Select @Ch2 = '整'

end

Select @ReturnValue = @ReturnValue + @Ch1 + @Ch2

select @i = @i+1
end

--最后将多余的零去掉
If CharIndex('仟仟',@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, '仟仟', '仟')

If CharIndex('佰佰',@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, '佰佰', '佰')

If CharIndex('零元',@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, '零元', '元')

If CharIndex('零万',@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, '零万', '万')

If CharIndex('零亿',@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, '零亿', '亿')

If CharIndex('零整',@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, '零整', '整')

If CharIndex('零佰',@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, '零佰', '零')

If CharIndex('零仟',@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, '零仟', '零')

If CharIndex('元元',@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, '元元', '元')

Select @ReturnValue
GO