-
2010. 2. 10. 10:35 프로그래밍 언어/Pascal
파스칼 언어로 만든 용량 환산 함수 입니다.(델파이, 라자루스)
function TMainForm.GetSize(fvalue: int64): String;
const
S:array [0..4] of String = ('B','KB','MB','GB','TB','FB');
var
size: Double;
i: Byte;
begin
i:=i xor i;
if fvalue<1024 then
begin
Result:=IntToStr(fvalue)+S[i];
Exit;
end;
try
size:=fvalue/1024;
except
size:=fvalue/(1024*1024);
Inc(i);
end;
Inc(i);
repeat
try
size:=size/1024;
except
size:=size/(1024*1024);
Inc(i);
end;
Inc(i);
until (size<1024);
Result:=Format('%f',[size])+S[i];
end;
function TMainForm.GetSize(fvalue: int64): String;
const
S:array [0..4] of String = ('B','KB','MB','GB','TB','FB');
var
size: Double;
i: Byte;
begin
i:=i xor i;
if fvalue<1024 then
begin
Result:=IntToStr(fvalue)+S[i];
Exit;
end;
try
size:=fvalue/1024;
except
size:=fvalue/(1024*1024);
Inc(i);
end;
Inc(i);
repeat
try
size:=size/1024;
except
size:=size/(1024*1024);
Inc(i);
end;
Inc(i);
until (size<1024);
Result:=Format('%f',[size])+S[i];
end;
Posted by Nightly Luna