zoukankan      html  css  js  c++  java
  • 转写了个金额大写转换的函数

    /********************************************************
    作者:(wleii165@yahoo.com)
    版本:1.0
    创建时间:20020227
    修改时间:
    功能:小写金额转换成大写
    参数:n_LowerMoney 小写金额
              v_TransType 种类 -- 1: directly translate, 0: read it in words 
    输出:大写金额
    ********************************************************/
    CREATE PROCEDURE dbo.L2U 
    (
    @n_LowerMoney numeric(15,2),
    @v_TransType int,
    @RET VARCHAR(200) output
    )
     AS 
      
    Declare @v_LowerStr VARCHAR(200) -- 小写金额 
    Declare @v_UpperPart VARCHAR(200) 
    Declare @v_UpperStr VARCHAR(200) -- 大写金额
    Declare @i_I int

    set nocount on

    select @v_LowerStr = LTRIM(RTRIM(STR(@n_LowerMoney,20,2))) --四舍五入为指定的精度并删除数据左右空格

    select @i_I = 1
    select @v_UpperStr = ''

    while ( @i_I <= len(@v_LowerStr))
    begin
          select @v_UpperPart = case substring(@v_LowerStr,len(@v_LowerStr) - @i_I + 1,1)
                                WHEN  '.' THEN  '元'
                                WHEN  '0' THEN  '零'
                                WHEN  '1' THEN  '壹'
                                WHEN  '2' THEN  '贰'
                                WHEN  '3' THEN  '叁'
                                WHEN  '4' THEN  '肆'
                                WHEN  '5' THEN  '伍'
                                WHEN  '6' THEN  '陆'
                                WHEN  '7' THEN  '柒'
                                WHEN  '8' THEN  '捌'
                                WHEN  '9' THEN  '玖'
                                END
                              + 
                                case @i_I
                                WHEN  1  THEN  '分'
                                WHEN  2  THEN  '角'
                                WHEN  3  THEN  ''
                                WHEN  4  THEN  ''
                                WHEN  5  THEN  '拾'
                                WHEN  6  THEN  '佰'
                                WHEN  7  THEN  '仟'
                                WHEN  8  THEN  '万'
                                WHEN  9  THEN  '拾'
                                WHEN  10  THEN  '佰'
                                WHEN  11  THEN  '仟'
                                WHEN  12  THEN  '亿'
                                WHEN  13  THEN  '拾'
                                WHEN  14  THEN  '佰'
                                WHEN  15  THEN  '仟'
                                WHEN  16  THEN  '万'
                                ELSE ''
                                END
    select @v_UpperStr = @v_UpperPart + @v_UpperStr
    select @i_I = @i_I + 1
    end

    --------print  '//v_UpperStr ='+@v_UpperStr +'//'

    if ( @v_TransType=0 )
    begin
    select @v_UpperStr = REPLACE(@v_UpperStr,'零拾','零') 
    select @v_UpperStr = REPLACE(@v_UpperStr,'零佰','零') 
    select @v_UpperStr = REPLACE(@v_UpperStr,'零仟','零') 
    select @v_UpperStr = REPLACE(@v_UpperStr,'零零零','零')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零零','零')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零角零分','整')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零分','整')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零角','零')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零亿零万零元','亿元')
    select @v_UpperStr = REPLACE(@v_UpperStr,'亿零万零元','亿元')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零亿零万','亿')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零万零元','万元')
    select @v_UpperStr = REPLACE(@v_UpperStr,'万零元','万元')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零亿','亿')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零万','万')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零元','元')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零零','零')
    end

    -- 对壹元以下的金额的处理 
    if ( substring(@v_UpperStr,1,1)='元' )
    begin
         select @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
    end

    if (substring(@v_UpperStr,1,1)= '零')
    begin
         select @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
    end

    if (substring(@v_UpperStr,1,1)='角')
    begin
         select @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
    end

    if ( substring(@v_UpperStr,1,1)='分')
    begin
         select @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
    end

    if (substring(@v_UpperStr,1,1)='整')
    begin
         select @v_UpperStr = '零元整'
    end

    select @RET=@v_UpperStr

    GO

    调用过程:

    declare @RET varchar(200)

    exec L2U 567983.897,1,@RET output

    select @RET

    ---------------------------------------------------------------------------------------------------------------------

     CREATE FUNCTION GetChineseNum (@inputId money)   
    RETURNS Nvarchar(4000) AS  
    BEGIN 
     declare @rV Nvarchar(4000)

    declare @tmpstr Nvarchar(4000),@M Nvarchar(4000),@K Nvarchar(4000),@I numeric(38,2),
     @J int,@lastJ int,@LastV Nvarchar(10),@LastF Nvarchar(10),@LastE Nvarchar(10),@LastVE Nvarchar(10)
    set @I=@inputId
    set set @K=N''

    if @I<0 
    begin
     set @I=0-@I
     set @K=N'负'
    end
    if @I=0  return N'零元整'

    select @tmpstr=N'零壹贰叁肆伍陆柒捌玖分角元拾佰仟万拾佰仟亿拾佰仟',@M=cast(cast(@I*100 as bigint) as varchar(800)),@J=len(@M),@LastVE=N''
    while @J>=1
    begin
     set @LastF=substring(@tmpstr, cast(substring(@M,len(@M)-@J+1,1) as bigint)+1,1)
     set @LastE=substring(@tmpstr,10+@J,1)
     if @LastF<>N'零'
     begin
      if @LastV=N'零'
       if (@lastJ>=7 and @J<7) or (@lastJ>=11 and @J<11 ) or (@lastJ>=3 and @J<=2)
        if @J<=2 and @lastJ<=3
         set @K=@K+@LastVE+@LastF+@LastE
        else
         set @K=@K+@LastVE+@LastV+@LastF+@LastE
       else
        set @K=@K+@LastV+@LastF+@LastE
      else
       set @K=@K+@LastF+@LastE
      select @lastJ=@J,@LastVE=N''
     end
     else
     begin
      if @LastVE=N'' and @lastJ>11 set @LastVE=N'亿'
      if @LastVE=N'' and @lastJ>7 and @lastJ<10 set @LastVE=N'万'
      if @LastVE=N'' and @lastJ>3 and @lastJ<6 set @LastVE=N'元'
      if @LastVE=N'' and @lastJ>2 set @LastVE=N'零'
      if @LastV<>N'零' set @lastJ=@J
     end
     set @LastV=@LastF
     set @J=@J-1
    end
    if @lastJ>=6 set @K=@K+@LastVE
    if @lastJ>=3 set @K=@K+N'元'
    if @lastJ>1 or (@lastJ=1 and @LastV=N'零') set @K=@K+N'整'

    set @rV=@K

     return @rV
    END

  • 相关阅读:
    2、Windows 系统下安装 IntelliJ IDEA
    1、IntelliJ IDEA 使用说明
    C# static的用法详解
    wpf 加载窗体界面时出现异常System.IO.FileNotFoundException
    ObservableCollection绑定到TextBox
    Lambda表达式(转载)
    C#中out和ref之间的区别 转载
    WPF序列化与反序列化
    软件版本号规范与命名原则 转载
    WPF DataGrid滚动条滑动的时候背景色错乱或显示不全
  • 原文地址:https://www.cnblogs.com/accumulater/p/6806922.html
Copyright © 2011-2022 走看看