用Delphi编制金额大写转换程序

2016-01-29 14:16 39 1 收藏

用Delphi编制金额大写转换程序,用Delphi编制金额大写转换程序

【 tulaoshi.com - Delphi 】

 

  在从事与财务相关的软件开发过程中,通常要求将小写金额转换成相应的大写金额,并打印在大写金额栏中。下面是用Delphi3.0编制的一个转换函数,能够方便的在程序中调用,并返回字符串。

  1.定义函数num—str

  function num—str(ls: Variant): String;

  var

   dx—sz,dx—dw,str—int,str—dec,dx—str,fu:string;

   a,b,b2,c,d:string;

   num—int,num—dec,len—int,i,a—int,pp:integer;

  //dx—str为返回字符串

  begin

  dx—sz:=′零壹贰叁肆伍陆柒捌玖′;

  dx—dw:=′万仟佰拾亿仟佰拾万仟佰拾元′;

  //处理金额小于零情况

  if ls〈0 then

  begin

   ls:=ls(-1);

   fu:=′负′;

  end else fu:=′′;

  //取得整数值及整数串

  dx—str:=ls;

  if (ls〉0)and(ls〈1) then dx—str:=′0′+dx—str;

  pp:=pos(′.′,dx—str);

  if pp〉0 then str—int:=copy(dx—str,1,pos(′.′,dx—str)-1)

  else str—int:=dx—str;

  num—int:=strtoint(str—int);

  //取得小数值及小数串

  if (ls〉0)and(ls〈1) then num—dec:=ls100

  else num—dec:=(ls-num—int)100;

  str—dec:=inttostr(num—dec);

  len—int:=Length(str—int);

   dx—str:=′′;

  //转换整数部分

   for i:=1 to len—int do

   begin

  //a为小写数字字符,b为对应的大写字符

  //c为对应大写单位,d为当前大写字符串的最后一个汉字

   a:=copy(str—int,i,1);

   a—int:=strtoint(a);

   b:=copy(dx—sz,(a—int2+1),2);

   c:=copy(dx—dw,((13-len—int+i-1)2+1),2);

   if dx—str〈〉′′ then

   d:=copy(dx—str,Length(dx—str)-1,2)

   else d:=′′;

   if (b=′零′)and((d=′零′)or(b=b2)or(c=′元′)or(c=′万′)or(c=′亿′)) then b:=′′;

   if (a=′0′)and(c〈〉′元′)and(c〈〉万′′)and(c〈〉′亿′) then c:=′′;

   if ((c=′元′)or(c=′万′)or(c=′亿′))and (d=′零′)and(a=′0′) then

   begin

   dx—str:=copy(dx—str,1,Length(dx—str)-2);

   d:=copy(dx—str,Length(dx—str)-1,2);

   if ((c=′元′)and(d=′万′))or((c=′万′)and(d=′亿′)) then c:=′′;

   end;

   dx—str:=dx—str+b+c; b2:=b;

   end;

  //处理金额小于1的情况

  if Length(dx—str)〈=2 then dx—str:=′′;

  //转换小数部分

  if (num—dec〈10)and(ls〉0) then

  begin

  a—int:=strtoint(str—dec);

  b:=copy(dx—sz,(a—int2+1),2);

  if num—dec=0 then dx—str:=dx—str+′整′;

  if num—dec〉0 then dx—str:=dx—str+′零′+b+′分′;

  end;

  if num—dec〉=10 then

  begin

  a—int:=strtoint(copy(str—dec,1,1));

  a:=copy(dx—sz,(a—int2+1),2);

  a—int:=strtoint(copy(str—dec,2,1));

  b:=copy(dx—sz,(a—int2+1),2);

  if a〈〉′零′ then a:=a+′角′;

  if b〈〉′零′ then b:=b+′分′

  else b:=′′;

  dx—str:=dx—str+a+b;

   end;

   if ls=0 then dx—str:=′零元整′;

   dx—str:=fu+dx—str;

  //函数返回字符串

   Result:=dx—str;

  end;

  2.调用方法

  函数参数采用Variant类型,调用时参数值可以是实型,也可以是字符串,非常方便,下面举例说明:

  新建窗口,在相应pas文件中加入num—str函数,并在窗口中添加Button1和Edit1、Edit2控件,双击Button1输入以下代码,运行程序即可:

   procedure TForm1.Button1Click(Sender: TObject);

   begin

   Edit1.text:=num—str(202055010.32);

   //也可以在Edit2中输入数串调用

   //Edit1.text:=num—str(Edit2.text);

   end;

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/delphi/) 

来源:https://www.tulaoshi.com/n/20160129/1492896.html

延伸阅读
标签: word
Word快速输入大写金额方法   1、打开word文档,选择插入选项卡,单击符号选项组中的编号按钮。 2、弹出编号对话框,在编号文档框中输入我们需要转换成中文大写金额的阿拉伯数字金额,在编号类型文本框中选择壹,贰,叁,点击确定即可。 3、可以看到刚刚输入的阿拉伯数字金额,都变成了中文大写数字金额。 Word怎...
标签: Delphi
  当你完成一个应用软件的开发后,那么你还需要为该软件做一个规范化的安装程序,这是程序设计的最后一步,同时也是很重要的一步,因为运行安装程序往往是用户做的第一步操作。 很多报刊文章介绍了许多如何利用installshield等工具软件来制作安装程序的方法,这种办法可以很快建立起较常见的安装模式,但用这种办法也有一些...
标签: ASP
  Internet(或Intranet)上带权限的查询,只有“合法用户”才能进入。这种机制是通过Web程序实现的。在访问过程中,如果程序设计得不好,就会将用户口令暴露在地址栏里(举一个例子:http://www.mmm.nnn/default.asp ?superusername=john&passwd=john123,用户名john和密码john123全露出来了),这样系统就无保密和安全性可言了。怎样...
//******************************************************** // 模块:数字转换为中文大写 #include "stdafx.h" static char *unit1[] = { "拾", "佰", "仟" }; static char *unit2[] = { "万", "亿" }; static char *digital[] = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" }; //*******************************...
本程序通过调用kernel32.dll中的几个API 函数,搜索并列出系统中除本进程外的所有进程的ID、对应的文件说明符、优先级、CPU占有率、线程数、相关进程信息等有关信息,并可中止所选进程。 本程序运行时会在系统托盘区加入图标,不会出现在按Ctrl+Alt+Del出现的任务列表中,也不会在任务栏上显示任务按钮,在不活动或最小化时会自动隐...

经验教程

478

收藏

57
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部