轉大寫函式MoneyCn

hrdzkj發表於2013-07-15

http://www.2ccc.com/article.asp?articleid=3556
控制元件版本是:
----------
FastReport 3.23.12 Enterpise for d2006 (DeXter)

設定如下:
----------
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)

相關文章