金额大写转换函数

来源:互联网 发布:淘宝网游账号交易 编辑:程序博客网 时间:2024/05/17 02:41

 

 1//------------------转大写金额函数--------------------------------------------
 2function NumToChnStr(Value: Real): String;
 3const
 4  ChnUnit: array[0..13] of string = ('''''''''''''''''''''亿''''''');
 5  ChnNum : array[0..9] of string = ('''','''''''''''''''');
 6var
 7  I: Integer;
 8  StrValue, StrNum: String;
 9  ValueLen: Integer;
10begin
11  try
12
13    StrValue := IntToStr(Round(Value * 100));
14    ValueLen := Length(StrValue);
15    Result := '';
16    for I := 1 to ValueLen do
17      begin
18        StrNum := StrValue[I];
19        Result := Result + ChnNum[StrToInt(StrNum)] + ChnUnit[ValueLen - I];
20     end;
21        Result := StringReplace(Result, '零角''', [rfReplaceAll]);
22        Result := StringReplace(Result, '零分''', [rfReplaceAll]);
23        Result := StringReplace(Result, '零拾''', [rfReplaceAll]);
24        Result := StringReplace(Result, '零佰''', [rfReplaceAll]);
25        Result := StringReplace(Result, '零仟''', [rfReplaceAll]);
26        Result := StringReplace(Result, '零万''', [rfReplaceAll]);
27        //Result := StringReplace(Result, '零元', '元', [rfReplaceAll]);
28    while pos('零零',Result)<>0 do
29      Result := StringReplace(Result, '零零''', [rfReplaceAll]);
30    if pos('零元',Result)<>0 then
31      Result := StringReplace(Result, '零元''', [rfReplaceAll]);
32    if pos('',Result)=0 then
33      Result := Result+'';
34    if (pos('',Result)<>0) and (pos('',Result)=0) then
35      Result := StringReplace(Result, '''元零', [rfReplaceAll]);
36  except
37    MessageDlg('转换出错!',mtInformation,[mbOK],0);
38    exit;
39  end;
40end;
原创粉丝点击