Delphi

[델파이] 숫자를 한글숫자(금액 같은 경우)로...

Revers Tuna 2015. 5. 26. 20:32

function IntToKorNum(AValue: Int64): string;
const
  NumberChar: array['0'..'9'] of string = ('영', '일', '이', '삼', '사', '오', '육', '칠', '팔', '구');
  LevelChar: array[0..3] of string = ('', '십', '백', '천');
  DecimalChar: array[0..5] of string = ('', '만', '억', '조', '경', '현');
var
  vStr: string;
  vDecimal: Boolean;
  i, vLevel: Integer;
begin
  Result := '';

  vStr := IntToStr(AValue);
  vDecimal := False;

  for i := 1 to Length(vStr) do
  begin
    vLevel := Length(vStr) -i;

    if vStr[i] <> '0' then
    begin
      vDecimal := True;

      if vLevel mod 4 = 0 then
      begin
        Result := Result + NumberChar[vStr[i]] + Decimalchar[vLevel div 4];
        vDecimal := False;
      end
      else
        Result := Result + NumberChar[vStr[i]] + LevelChar[vLevel mod 4];
    end
    else if (vLevel mod 4 = 0) and vDecimal then
    begin
      Result := Result + DecimalChar[vLevel div 4];
      vDecimal := False;
    end;

  end;
end;