Форум: "KOL";
Текущий архив: 2014.11.23;
Скачать: [xml.tar.bz2];
ВнизРазмер файла строчкой в KOL. Найти похожие ветки
← →
Валера (2009-10-13 03:10) [0]Я пишу без использования SysUtils !
Нужна альтернатива этим функциям:
function FileSizeToStr(const FileSize: Int64): string;
begin
if FileSize = 1 then
Result := "1 byte"
else if FileSize < 1024 then
Result := Format("%d bytes", [FileSize])
else if FileSize < 1024 * 1024 then
Result := Format("%lu KB", [FileSize / 1024])
else if FileSize < 1024 * 1024 * 1024 then
Result := Format(" MB", [FileSize / (1024 * 1024)])
else
Result := Format("%.3f GB", [FileSize / (1024 * 1024 * 1024)]);
end;
function FileSizeToString(FileSize: Integer): string;
const
ONE_K = 1024;
ONE_MB = 1024 * ONE_K;
ONE_GB = 1024 * ONE_MB;
begin
// Decide whether we should report filesize in GB, MB, KB or Bytes
if FileSize >= ONE_GB then
Result := Format("%.2f GB", [FileSize / ONE_GB])
else if FileSize >= ONE_MB then
Result := Format("%.2f MB", [FileSize / ONE_MB])
else if FileSize >= ONE_K then
Result := Format("%.2f KB", [FileSize / ONE_K])
else
Result := Format("%d Bytes", [FileSize]);
end;
← →
Валера (2009-10-13 13:15) [1]Написал так, вроде работает...
function DoubleToStrEx(d: double; CountAfterDot: integer): string;
var a: integer;
begin
Result := Double2Str(d);
a := Pos(".", Result);
if a >= 0 then
Result := copy(Result, 1, a + CountAfterDot);
end;
function FileSizeToString(FileSize: Integer): string;
const
ONE_K = 1024;
ONE_MB = 1024 * ONE_K;
ONE_GB = 1024 * ONE_MB;
begin
if FileSize >= ONE_GB then
Result := Format("%s GB", [DoubleToStrEx(FileSize / ONE_GB, 2)])
else if FileSize >= ONE_MB then
Result := Format("%s MB", [DoubleToStrEx(FileSize / ONE_MB, 2)])
else if FileSize >= ONE_K then
Result := Format("%s KB", [DoubleToStrEx(FileSize / ONE_K, 2)])
else
Result := Format("%d Bytes", [FileSize]);
end;
Страницы: 1 вся ветка
Форум: "KOL";
Текущий архив: 2014.11.23;
Скачать: [xml.tar.bz2];
Память: 0.44 MB
Время: 0.003 c