开发者社区> 技术小甜> 正文

人民币转大写

简介:
+关注继续查看
function 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<length(txt))do
begin
if (p^>'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<ilen then //如果低位也为零,低位零不显示
if (strarray[i+1]= '') or (strarray[i+1]= '零') then
begin
//strarray[i+1]:= '';
              strarray[i]:= '';
end;
if i=n then strarray[i]:='';
         strlevel[i]:='';
end;
end; //case
end;
//先处理 小数点部分
if m>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; //for
Result := Result + '整';

end;














本文转自鹅倌51CTO博客,原文链接:http://blog.51cto.com/kaixinbuliao/1741917 ,如需转载请自行联系原作者


版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
scss 文件里的特殊符号 - % 百分号和 $美元符号
scss 文件里的特殊符号 - % 百分号和 $美元符号
45 0
数字转为人民币大写汉字输出(大力看了都喊nb的详细教程)
将用户输入的数字转为人民币大写汉字输出。(壹贰叁肆伍陆柒捌玖拾亿万佰千零圆),我们的目的是将一个数字转换成为我们所读出来的汉语写法,类似于银行中用到的转换,比较适合python的初学者来练习。
168 0
(四)全球数字人民币 CBDC —— e-CNY
关键词:DC/EP、CBDC、e-CNY基础名词CBDC:central bank digital currency —— 中央银行数字货币DC/EP:Digital Currency/Electronic Payment —— 数字货币/电子支付e-CNY:中国的CBDC6个国际CBDC资讯时间:2022-02巴哈马:CBOB,Sand Dollar,沙币加拿大:BOC:加中行,建设中。中国:P
636 0
c#金额转换成中文大写金额
原文:c#金额转换成中文大写金额 2018-08-24 转别人 c#金额转换成中文大写金额 /// /// 金额转换成中文大写金额 /// /// eg:10.
1373 0
+关注
技术小甜
文章
问答
视频
文章排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载