MyChat Scripts Engine: IntToKbyte
Function to get a short text format of the file's size. In bytes, kilobytes, megabytes or gigabytes (depends on initial size).
Syntax
function IntToKbyte(iValue: int64): string;
Parameters and return values
Parameter |
Type |
Value |
iValue |
int64 |
size in bytes that you need to convert into a short format string. |
Function result
Text string, a short entry of the file's size. For example "1 GB" or "18.4 KB".
Example
begin
var
iSizes: array[1..10] of int64;
i: integer;
iSizes[1] := 13;
iSizes[2] := 4478;
iSizes[3] := 78336;
iSizes[4] := 694272;
iSizes[5] := 5945425;
iSizes[6] := 13002342;
iSizes[7] := 245366784;
iSizes[8] := 3693671874;
iSizes[9] := 13636521164;
iSizes[10] := 143881404416;
for i := 1 to 10 do
mLogScript(IntToKbyte(iSizes[i]) + ', ' + IntToStr(iSizes[i]) + ' bytes', '');
end.
Script work result
[19:24:52] (Log "IntToKbyte"): 13 B, 13 bytes
[19:24:52] (Log "IntToKbyte"): 4.37 KB, 4478 bytes
[19:24:52] (Log "IntToKbyte"): 76.5 KB, 78336 bytes
[19:24:52] (Log "IntToKbyte"): 678 KB, 694272 bytes
[19:24:52] (Log "IntToKbyte"): 5.67 MB, 5945425 bytes
[19:24:52] (Log "IntToKbyte"): 12.4 MB, 13002342 bytes
[19:24:52] (Log "IntToKbyte"): 234 MB, 245366784 bytes
[19:24:52] (Log "IntToKbyte"): 3.44 GB, 3693671874 bytes
[19:24:52] (Log "IntToKbyte"): 12.7 GB, 13636521164 bytes
[19:24:52] (Log "IntToKbyte"): 134 GB, 143881404416 bytes
[19:24:52] (Run "IntToKbyte"): Script operation time: 4 ms
[19:24:52] (Run "IntToKbyte"): Script done successfully.