程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 用Delphi將商品金額小寫轉大寫

用Delphi將商品金額小寫轉大寫

編輯:Delphi

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                        //小數點的位置  Begin    tmps := Decimal + '.';
    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;

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved