본문 바로가기
Delphi/프로시저-함수

숫자에 콤마 찍어주기

by MonoSoft 2024. 3. 9.
728x90
반응형

숫자에 콤마 찍어주기

 

728x90

 

{

********************************************************************************

** **

** 숫자에 화폐단위 000,000,000~ 처럼 3단위로 콤마를 삽입시켜 준다. **

** 999,999,999,999,999 단위 까지 가능함. 999조 **

** **

********************************************************************************

}

Function Comma(I : Double) : String;

var

StrTmp : String;

Cunt, J1, J2, K, L : Integer;

Begin

Cunt := 0;

L := 3;

StrTmp := FloatToStr(I);

Cunt := Length(StrTmp);

J1 := Cunt DIV L;

J2 := Cunt MOD L;

If (J1 >= 1) and (J2 = 0) Then

Begin

For K := 0 to J1-2 do

Begin

Insert(',',StrTmp, Cunt - L + 1);

Cunt := Cunt - L;

End;

End

Else If (J1 >= 1) and (J2 > 0) Then

Begin

For K := 0 to J1-1 do

Begin

Insert(',',StrTmp, Cunt - L + 1);

Cunt := Cunt - L;

End;

End;

Result := StrTmp;

End;

 

str=Format('%.0n',[val/1]);

Edit1.Text := FormatCurr('#,##0', StrToIntDef(Edit1.Text, 0));

str := formatfloat(',', integer);

 

728x90
반응형

댓글