当前位置:编程学习 > Delphi >>

小写金额转换为大写

 

 


//本函数用于将小于十万亿元的小写金额转换为大写
Function NtoC( n0 :real) :String;
  Function IIF( b :boolean; s1,s2 :string) :string;
    begin if b then IIF:= s1 else IIF:=s2;
    end; //本函数的功能一目了然: 当b为真时返回s1,否则返回s2
  Const c= ’零壹贰叁肆伍陆柒捌玖◇分角圆拾佰仟万拾佰仟亿拾佰仟万’;
  var L,i,n :integer;   Z :boolean;   s,s1,s2 :string;
begin
  s:= FormatFloat( ’0.00’, ABS(n0));
  L:= Length( s);
  Z:= n0<1;
  For i:= 1 To L-3 do
    begin
    n:= StrToInt( s[ L-i-2]);
    s1:=IIf((n=0)And(Z Or (i=9) Or (i=5) Or (i=1)), ’’, Copy( c, n*2+1, 2))
      + IIf((n=0)And((i<>9)And(i<>5)And(i<>1) Or Z And(i=1)),’’,Copy(c,(i+13)*2-1,2))
      + s1;
    Z:= (n=0);
    end;
  Z:= False;
  For i:= 1 To 2 do
    begin
    n:= StrToInt( s[ L-i+1]);
    s2:= IIf((n=0)And((i=1) Or (i=2)And(Z Or (n0<1))), ’’, Copy( c, n*2+1, 2))
       + IIf( (n>0), Copy( c,(i+11)*2-1, 2), IIf( (i=2) Or Z, ’’,’整’))
       + s2;
    Z:= (n=0);
    end;
  For i:= 1 To Length( s1) do If Copy(s1, i, 4) = ’亿万’ Then Delete(s1,i+2,2);
  NtoC:= IIf(n0=0, ’零’, IIF(n0<0, ’-’,’’)+ s1+s2);
End;
//对于大写金额中“零”的用法,习惯不同,清指正。
//在FoxPro、VB中,IIF都是内部函数。但Delphi没有,只得自己定义。

 

补充:软件开发 , Delphi ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,