FastReport调用Delphi中的自定义函数(人民币大写金额)

人民币大写金额转换函数
function  MoneyToCn(ANumberic: Real): string;
const
  s1: string 
=   ' 零壹贰叁肆伍陆柒捌玖 ' ;
  s2: string 
=   ' 分角元拾佰仟万拾佰仟亿拾佰仟万 ' ;

function  StrTran( const  S, s1, s2: string): string;
begin
  Result :
=  StringReplace(S, s1, s2, [rfReplaceAll]);
end ;
var
  S, dx: string;
  i, Len: Integer;

begin
  
if  ANumberic  <   0   then
  
begin
    dx :
=   ' ' ;
    ANumberic :
=   - ANumberic;
  
end ;

  S :
=  Format( ' %.0f ' , [ANumberic  *   100 ]);
  Len :
=  Length(S);
  
for  i : =   1   to  Len  do
  dx :
=  dx  +  Copy(s1, (Ord(S[i])  -  Ord( ' 0 ' ))  *   2   +   1 2 +  Copy(s2, (Len  -  i) *   2   +   1 2 );

  dx :
=  StrTran(StrTran(StrTran(StrTran(StrTran(dx,  ' 零仟 ' ' ' ),  ' 零佰 ' , ' ' ), ' 零拾 ' ' ' ),  ' 零角 ' ' ' ),  ' 零分 '
    
' ' );
  dx :
=  StrTran(StrTran(StrTran(StrTran(StrTran(dx,  ' 零零 ' ' ' ),  ' 零零 ' , ' ' ), ' 零亿 ' ' 亿 ' ),  ' 零万 ' ' ' ),  ' 零元 '
    
' ' );
  
if  dx  =   ' '   then
    Result :
=   ' 零元整 '
  
else
    Result :
=  StrTran(StrTran(dx,  ' 亿万 ' ' 亿零 ' ),  ' 零整 ' ' ' );
end ;

在Create中向FastReprot添加函数
procedure  Create(Sender: TObject);
begin
  frxReport1.AddFunction(
' function MoneyToCn(ANumberic: Real): String; ' , ' Myfunction ' , ' 人民币大写金额转换函数 ' );
end ;

在FastReport用户函数事件中添加
function  frxReport1UserFunction( const  MethodName: string;  var  Params: Variant): Variant;
begin
  
if  UpperCase(MethodName)  =  UpperCase( ' MoneyToCn ' then
  Result :
=  MoneyToCn(Params[ 0 ]);
end ;

转载于:https://www.cnblogs.com/sonicit/archive/2008/06/03/1213082.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值