zoukankan      html  css  js  c++  java
  • FastReport调用Delphi中的人民币大写转换自定义函数

    FastReport调用Delphi中的人民币大写转换自定义函数

     

    FastReport调用Delphi中的人民币大写转换自定义函数

    function TJzpzEdit1.MoneyCn(mmje: Double): 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 mmje < 0 then

    begin

    dx := ‘负’;

    mmje := -mmje;

    end;

    S := Format(‘%.0f’, [mmje * 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;

    //////////

    procedure TJzpzEdit1.FormCreate(Sender: TObject);

    begin

    frxReport1.AddFunction(‘function MoneyCn(mmje: Double): String;’,'Myfunction’,'小写金额转大写的函数’);

    end;

    //////////

    function TJzpzEdit1.frxReport1UserFunction(const MethodName: string;

    var Params: Variant): Variant;

    begin

    if UpperCase(MethodName) = UpperCase(‘MoneyCn’) then

    Result := MoneyCn(Params[0]);

    end;

    //////////

    报表中调用方法

    MoneyCn(50000000)

  • 相关阅读:
    tryparse的用法,^0*[1-9]d*$
    寻找指定的进程然后杀死的代码写法
    P2421 [NOI2002]荒岛野人
    P2568 GCD
    P1445 [Violet]樱花
    P3119 [USACO15JAN]草鉴定Grass Cownoisseur
    P1314 聪明的质监员
    P3811 【模板】乘法逆元
    P3943 星空
    P3225 [HNOI2012]矿场搭建
  • 原文地址:https://www.cnblogs.com/m0488/p/3772937.html
Copyright © 2011-2022 走看看