将小写金额转换为英文

CREATE FUNCTION [dbo].[f_num_eng] (@num numeric(15,2))
RETURNS varchar(400) WITH ENCRYPTION
AS
BEGIN
--All rights reserved. pbsql
  DECLARE @i int,@hundreds int,@tenth int,@one int
  DECLARE @thousand int,@million int,@billion int
  DECLARE @numbers varchar(400),@s varchar(15),@result varchar(400)
  SET @numbers='one       two       three     four      five      '
              +'six       seven     eight     nine      ten       '
              +'eleven    twelve    thirteen  fourteen  fifteen   '
              +'sixteen   seventeen eighteen  nineteen  '
              +'twenty    thirty    forty     fifty     '
              +'sixty     seventy   eighty    ninety    '
  SET @s=RIGHT('000000000000000'+CAST(@num AS varchar(15)),15)
  SET @billion=CAST(SUBSTRING(@s,1,3) AS int)--将12位整数分成4段:十亿、百万、千、百十个
  SET @million=CAST(SUBSTRING(@s,4,3) AS int)
  SET @thousand=CAST(SUBSTRING(@s,7,3) AS int)
  SET @result=''
  SET @i=0
  WHILE @i<=3
  BEGIN
    SET @hundreds=CAST(SUBSTRING(@s,@i*3+1,1) AS int)--百位0-9
    SET @tenth=CAST(SUBSTRING(@s,@i*3+2,1) AS int)
    SET @one=(CASE @tenth WHEN 1 THEN 10 ELSE 0 END)+CAST(SUBSTRING(@s,@i*3+3,1) AS int)--个位0-19
    SET @tenth=(CASE WHEN @tenth<=1 THEN 0 ELSE @tenth END)--十位0、2-9
    IF (@i=1 and @billion>0 and (@million>0 or @thousand>0 or @hundreds>0)) or
       (@i=2 and (@billion>0 or @million>0) and (@thousand>0 or @hundreds>0)) or
       (@i=3 and (@billion>0 or @million>0 or @thousand>0) and (@hundreds>0))
      SET @result=@result+', '--百位不是0则每段之间加连接符,
    IF (@i=3 and (@billion>0 or @million>0 or @thousand>0) and (@hundreds=0 and (@tenth>0 or @one>0)))
      SET @result=@result+' and '--百位是0则加连接符AND
    IF @hundreds>0
      SET @result=@result+RTRIM(SUBSTRING(@numbers,@hundreds*10-9,10))+' hundred'
    IF @tenth>=2 and @tenth<=9
    BEGIN
      IF @hundreds>0
        SET @result=@result+' and '
      SET @result=@result+RTRIM(SUBSTRING(@numbers,@tenth*10+171,10))
    END
    IF @one>=1 and @one<=19
    BEGIN
      IF @tenth>0
        SET @result=@result+'-'
      ELSE
        IF @hundreds>0
          SET @result=@result+' and '
      SET @result=@result+RTRIM(SUBSTRING(@numbers,@one*10-9,10))
    END
    IF @i=0 and @billion>0
      SET @result=@result+' billion'
    IF @i=1 and @million>0
      SET @result=@result+' million'
    IF @i=2 and @thousand>0
      SET @result=@result+' thousand'
    SET @i=@i+1
  END
  IF SUBSTRING(@s,14,2)<>'00'
  BEGIN
    SET @result=@result+' point '
    IF SUBSTRING(@s,14,1)='0'
      SET @result=@result+'zero'
    ELSE
      SET @result=@result+RTRIM(SUBSTRING(@numbers,CAST(SUBSTRING(@s,14,1) AS int)*10-9,10))
    IF SUBSTRING(@s,15,1)<>'0'
      SET @result=@result+' '+RTRIM(SUBSTRING(@numbers,CAST(SUBSTRING(@s,15,1) AS int)*10-9,10))
  END
  RETURN(@result)
END
GO
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
功能强大的文本编辑软件,包含70种功能,操作简单(单击功能条目,显示功能说明,双击条目,就可以完成操作),一目了然!尤其是网页文本等宽行合并及格式化功能,实在是居家办公必备工具! 其他功能包括: 清除首尾空格 清除所有空格 清除所有字母 清除所有数字 清除所有符号 清除字符串 清除所有HTML标记 行左增加字符串 行右增加字符串 行左插入字符串 行右插入字符串 行左添加序号1、 行左清除序号1、 替换:书名号 替换:字符串 替换:通配符 替换:括号内 替换:多字符对应 替换:多字符串对应 删除空白行 删包含值行 删除前面行 删除后面行 删除指定行 删除重复行 删除字符串前文本 删除字符串后文本 删除左面几位字符 删除右面几位字符 添加书名号 查找内容 单文本行合并 重复行编号 字符串过滤 按分隔符分行 文本比较:标记相同行 文本比较:删除相同行 文本合并:前后合并 文本合并:左右合并 提取所有邮箱地址 提取所有手机号 提取所有链接文件名 提取所有固定电话 提取所有网址 提取重复行 提取包含字符行 提取包含字符串行 提取两字符之间文本 提取两字符串之间文本 繁体转换简体 简体转换繁体 字母转换大写 字母转换小写 英文首字母大写 汉字转换拼音 全角转半角 半角转全角 金额小写转换大写 金额大写转换小写 AES加密 AES解密 MD5取值 SHA1取值 Base64加密 Base64解密 URL编码 URL解码 音乐CUE文件曲名替换 音乐CUE文件曲名提取 多音乐文件生成CUE文件
//--------------------------------------------------------------------------- #include #pragma hdrstop #include #include #include #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- AnsiString TForm1::num_str(Variant ls) { AnsiString dx_sz,dx_dw,str_int,str_dec,dx_str,fu; AnsiString a,b,b2,c,d; int num_int,num_dec,len_int,i,a_int,pp; //dx—str为返回字符串 dx_sz="零壹贰叁肆伍陆柒捌玖"; dx_dw="万仟佰拾亿仟佰拾万仟佰拾元"; //dx_dw="元拾佰仟万拾佰仟亿拾佰仟万"; //处理金额小于零情况 if (ls0)&&(ls0) str_int=dx_str.SubString (1,dx_str.AnsiPos(".")-1);} else str_int=dx_str; num_int=StrToInt(str_int*100)/100; str_int=(str_int*100)/100; //取得小数值及小数串 if ((ls>0)&&(ls<1))num_dec=ls*100; else num_dec=(ls-num_int)*100; str_dec=IntToStr(num_dec); // ShowMessage(str_dec); len_int=str_int.Length(); dx_str=""; // ShowMessage(len_int); // ShowMessage((ls-num_int)*100); //转换整数部分 // for i:=1 to len—int do for (i=1;i<=len_int;i++) { //a为小写数字字符,b为对应的大写字符 //c为对应大写单位,d为当前大写字符串的最后一个汉字 a=str_int.SubString(i,1); a_int=StrToInt(a); b=dx_sz.SubString((a_int*2+1),2);// b=copy(dx_sz,(a_int2+1),2); c=dx_dw.SubString(((14-len_int+i-1)*2-1),2); if(dx_str!="")d=dx_str.SubString((dx_str.Length()-1),2); else d=""; if ((b=="零")&&((d=="零")||(b==b2)||(c=="元")||(c=="万")||(c=="亿"))) b=""; if ((a=="0")&&(c!="元")&&(c!="万")&&(c!="亿"))c=""; if (((c=="元")||(c=="万")||(c=="亿"))&&(d=="零")&&(a=="0")) {dx_str=dx_str.SubString(1,dx_str.Length()-2); d=dx_str.SubString(dx_str.Length()-1,2); if (((c=="元")&&(d=="万"))||((c=="万")&&(d=="亿")))c=""; } dx_str=dx_str+b+c; b2=b; // ShowMessage(a+";"+b+";"+c+";"+d); } //处理金额小于1的情况 if (dx_str.Length()<=2)dx_str=""; //转换小数部分 if ((num_dec0)) { a_int=StrToInt(str_dec); //ShowMessage(a_int); b=dx_sz.SubString((a_int*2+1),2); if (num_dec==0) dx_str=dx_str+"整"; if(num_dec>0)dx_str=dx_str+"零"+b+"分"; } if(num_dec>=10) { a_int=StrToInt(str_dec.SubString(1,1)); a=dx_sz.SubString((a_int*2+1),2); a_int=StrToInt(str_dec.SubString(2,1)); b=dx_sz.SubString((a_int*2+1),2); if (a!="零")a=a+"角"; if (b!="零")b=b+"分"; else b=""; dx_str=dx_str+a+b; } if (ls==0) dx_str="零元整"; dx_str=fu+dx_str; //函数返回字符串 return dx_str; } void __fastcall TForm1::Button1Click(TObject *Sender) { Edit2->Text=num_str(Edit1->Text); ShowMessage(Edit2->Text); } //---------------------------------------------------------------------------

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

pbsql

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值