Home > php教程 > php手册 > 金额阿拉伯数字转换为中文的自定义函数

金额阿拉伯数字转换为中文的自定义函数

WBOY
Release: 2016-06-13 10:05:17
Original
849 people have browsed it

CREATE FUNCTION ChangeBigSmall
(@ChangeMoney money)
RETURNS VarChar(100) AS
BEGIN
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 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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template