Mit Hilfe der
Unit StrUtils kann man die Funktion nahezu 1:1 umkehren:
Delphi-Quellcode:
function FormatSizeR(S:
string): Int64;
const
UNITS:
Array[0..8]
of string = ('
B', '
KB', '
MB', '
GB', '
TB', '
PB', '
EB',
'
ZB', '
YB');
var
I: Integer;
E: Extended;
iIndex: Integer;
begin
I := Pos('
', S);
Assert(I > 0);
E := StrToFloat(Copy(S, 1, Pred(I)));
S := Copy(S, Succ(I));
iIndex := IndexText(S, UNITS);
if iIndex < 0
then
raise Exception.CreateFmt('
ungültige Einheit "%s"', [S]);
Result := Round(E * (1
shl (iIndex * 10)));
end;