Function DecimalToChineseCurrency(Decimal: String): String; Var
s, t : TStringList;
i, ti : Integer;
tmps : String;
IsDecimal : Integer; Begin IsDecimal := 0;
ti := 0;
For i := 1 To Length(Decimal) Do
Begin
If Decimal[i] = '.' Then
Begin Inc(IsDecimal);
ti := i;
End;
If Not (Decimal[i] In ['0'..'9', '.']) Or (IsDecimal > 1) Then
Begin Result := Decimal;
Exit;
End;
End;
If ti = 0 Then ti := Length(tmps);
tmps := Decimal;
s := TStringList.Create;
t := TStringList.Create;
Try s.Delimiter := ',';
t.Delimiter := ',';
s.CommaText := '0=零,1=壹,2=贰,3=叁,4=肆,5=伍,6=陆,7=柒,8=捌,9=玖';
t.CommaText := '-1=分,0=角,1=元,2=拾,3=佰,4=仟,5=万,6=拾,7=佰,8=仟,9=亿,10=拾,11=佰,12=仟,13=兆,14=拾,15=佰,16=仟';
ti := Length(tmps) - ti;
tmps := StringReplace(tmps, '.', '', [rfReplaceAll]);
For i := 1 To Length(tmps) Do
Begin
If (tmps[Length(tmps) - i + 1] = '0') And (i Mod 4 = 1) Then
Result := t.Values[IntToStr(i - ti)] + Result
Else
If (tmps[Length(tmps) - i + 1] = '0') And (i Mod 4 <> 1) Then
Result := s.Values[tmps[Length(tmps) - i + 1]] + Result
Else
Result := s.Values[tmps[Length(tmps) - i + 1]] + t.Values[IntToStr(i - ti)] + Result;
End;
While Pos('零零', Result) > 0 Do
Result := StringReplace(Result, '零零', '零', [rfReplaceAll]);
If Pos('零兆', Result) > 0 Then Result := StringReplace(Result, '零兆', '兆', [rfReplaceAll]);
If Pos('零亿', Result) > 0 Then Result := StringReplace(Result, '零亿', '亿', [rfReplaceAll]);
If Pos('零万', Result) > 0 Then Result := StringReplace(Result, '零万', '万', [rfReplaceAll]);
If Pos('零元', Result) > 0 Then Result := StringReplace(Result, '零元', '元', [rfReplaceAll]);
If Pos('兆亿', Result) > 0 Then Result := StringReplace(Result, '兆亿', '兆', [rfReplaceAll]);
If Pos('亿万', Result) > 0 Then Result := StringReplace(Result, '亿万', '亿', [rfReplaceAll]);
If Pos('兆万', Result) > 0 Then Result := StringReplace(Result, '兆万', '兆', [rfReplaceAll]);
Finally t.Free;
s.Free;
End;
End;
Function ChineseCurrencyToDecimal(ChineseCurrency: String): String; Var
s : TStringList;
i, ti : Integer; Begin s := TStringList.Create;
Try s.Delimiter := ',';
s.CommaText := '元=.,零=0,壹=1,贰=2,叁=3,肆=4,伍=5,陆=6,柒=7,捌=8,玖=9';
ti := Length(ChineseCurrency) Div 2;
For i := ti Downto 1 Do
Result := s.Values[ChineseCurrency[i * 2 - 1] + ChineseCurrency[i * 2]] + Result;
Finally s.Free;
End;
End;