博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数字转换大写人民币的delphi实现
阅读量:7029 次
发布时间:2019-06-28

本文共 3021 字,大约阅读时间需要 10 分钟。

function TForm1.changeRmb(const strRmb:string):string;var  txt,strhighlevel:string;  i,n,m,ilen,ipos:Integer;    //n记录整数部分长度,m记录分数部分长度   strarray,strlevel:array of string;   p:pchar;   ispoint:boolean;//判断是否有小数点begin  ispoint:=false;  result:='';  ipos:=0;  m:=0;  txt:=Trim(strRmb);  i:=1;   p:=PChar(txt);  //去除开头的0,以及. if ((txt[1]='0') and (txt[2]<>'.')) or (txt[1]='.') then  begin   ShowMessage('第1位不能为0或者是.,退出操作');   exit;  end;  //检查字符的合法性  while (i
'9') or ((p^<'0') and (P^<>'.')) then //ord('.')=46 begin ShowMessage(PChar('第'+inttostr(i)+'位包含非数字字符,将退出操作')); Exit; end; if P^='.' then if ispoint then begin showmessage('太多小数点,将退出!'); exit; end else begin ipos:=i; ispoint:=true; end; Inc(p); Inc(i); end;//while ilen:=Length(txt); if ispoint then begin n:=ipos-1; m:=ilen-ipos; end else n:=ilen; //判断是否超过万,或亿 if m>3 then begin ShowMessage('小数点后位数超过3,无法转换!'); Exit; end; SetLength(strarray,ilen+8); SetLength(strlevel,ilen+8); for i:=iLen downto 1 do begin if txt[i]<>'.' then case strtoint(txt[i]) of 1:strarray[i]:='壹'; 2:strarray[i]:='贰'; 3:strarray[i]:='叁'; 4:strarray[i]:='肆'; 5:strarray[i]:='伍'; 6:strarray[i]:='陆'; 7:strarray[i]:='柒'; 8:strarray[i]:='捌'; 9:strarray[i]:='玖'; 0: begin strarray[i]:='零'; if i
0 then begin for i:=m downto 1 do begin strlevel[ipos+i]:=''; case i-1 of 0: if txt[ipos+i]='0' then strarray[ipos+i]:='' else strlevel[ipos+i]:='角'; 1: if txt[ipos+i]='0' then strarray[ipos+i]:='' else strlevel[ipos+i]:='分'; 2: if txt[ipos+i]='0' then strarray[ipos+i]:='' else strlevel[ipos+i]:='厘'; end; Result:=strarray[ipos+i]+strlevel[ipos+i]+result; end; end; if ispoint and (txt[ipos-1]='0') and (n=1) then Result:=result+'' //如果少于1块时,不要显示元。 else Result:='元'+result; for i:=n downto 1 do begin case n-i of 0,4,8,12: strlevel[i]:=''; 1,5,9,13: strlevel[i]:='拾'; 2,6,10,14: strlevel[i]:='佰'; 3,7,11,15: strlevel[i]:='仟'; end; //case if (txt[i]='0') then strlevel[i]:=''; //要处理零 以及加上万、亿 if n-i=4 then begin if strarray[i]='零' then strarray[i]:=''; Result:=strarray[i]+strlevel[i]+'万'+result end else if n-i=8 then begin if strarray[i]='零' then strarray[i]:=''; Result:=strarray[i]+strlevel[i]+'亿'+result end //begin else if n-i=12 then begin if strarray[i]='零' then strarray[i]:=''; Result:=strarray[i]+strlevel[i]+'兆'+result end //begin else Result:=strarray[i]+strlevel[i]+result; end; //forend;

  

转载于:https://www.cnblogs.com/win32pro/p/7184050.html

你可能感兴趣的文章
技术人生:向前端人员学习
查看>>
【产品经理】产品经理的十大顶级错误
查看>>
“AIR SDK 0.0: AIR SDK location “...\devsdks\AIRSDK\Win” does not exist.”问题解决~
查看>>
识别Andriod APK签名证书类型
查看>>
获取CentOS软件源中的updates包
查看>>
git使用说明
查看>>
HTML5 Canvas实现黑客帝国文字掉落效果
查看>>
web 缓存
查看>>
【cocos2d-x 手游研发----怪物智能AI】
查看>>
值得拥有!精心推荐几款超实用的 CSS 开发工具
查看>>
NumberUtils、ArrayUtils和RandomUtils工具类用法
查看>>
转:MAVEN常用命令
查看>>
<三>年编程经验、何去何从?
查看>>
MVC应用程序,动态创建单选列表(RadioButtonList)
查看>>
miniupnpc
查看>>
Linux 引导过程内幕
查看>>
无法打开登录所请求的数据库 "ASPState"。登录失败。 用户 'NT AUTHORITY/SYSTEM' 登录失败。...
查看>>
Windows Phone开发(47):轻松调用Web Service
查看>>
ExecuteScalar的学习日志
查看>>
解决 dotNetZip 解压乱码的问题,支持ZIP分卷解压缩
查看>>