转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 数据库 >> Access >> 正文
金额阿拉伯数字转换为中文的自定义函数         ★★★★

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

作者:闵涛 文章来源:闵涛的学习笔记 点击数:640 更新时间:2009/4/22 21:23:28

  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<= @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, '元元', '元')

    return @ReturnValue

END


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Sql Server  · MySql
    · Access  · ORACLE
    · SyBase  · 其他
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台