* fix Num2Bytes (A bug in fucntion Num2Bytes. Due to the fact that when the fractional part of the size has a front significant zero, it is not shown. Test it on size 2204450816. Should show 2.05G, whereas KOL shows 2.5G) by Oleg N. Cher
git-svn-id: https://svn.code.sf.net/p/kolmck/code@168 91bb2d04-0c0c-4d2d-88a5-bbb6f4c1fa07
This commit is contained in:
parent
f74d2dee76
commit
1735bbe620
40
KOL.pas
40
KOL.pas
@ -16843,28 +16843,6 @@ begin
|
||||
Result := M + Result;
|
||||
end;
|
||||
|
||||
{$IFDEF _D2009orHigher} const Suffix: AnsiString = 'KMGT';
|
||||
{$ELSE} const Suffix = 'KMGT'; {$ENDIF}
|
||||
function Num2Bytes( Value : Double ) : KOLString;
|
||||
var V, I : Integer;
|
||||
begin
|
||||
Result := '';
|
||||
I := 0;
|
||||
while (Value >= 1024) and (I < 4) do begin
|
||||
Inc( I );
|
||||
Value := Value / 1024.0;
|
||||
end;
|
||||
Result := Int2Str( Trunc( Value ) );
|
||||
V := Trunc( (Value - Trunc( Value )) * 100 );
|
||||
if V <> 0 then begin
|
||||
if (V mod 10) = 0 then
|
||||
V := V div 10;
|
||||
Result := Result + ',' + Int2Str( V );
|
||||
end;
|
||||
if I > 0 then
|
||||
Result := Result + KOLString( Suffix[ I ] );
|
||||
end;
|
||||
|
||||
function S2Int( S: PKOLChar ): Integer;
|
||||
var M : Integer;
|
||||
begin
|
||||
@ -16890,6 +16868,24 @@ begin
|
||||
end;
|
||||
{$ENDIF PAS_VERSION}
|
||||
|
||||
function Num2Bytes(Value : Double): KOLString;
|
||||
const Suffix: KOLString = 'KMGT';
|
||||
var V, I : Integer;
|
||||
begin
|
||||
Result := '';
|
||||
I := 0;
|
||||
while (Value >= 1024) and (I < 4) do begin
|
||||
Inc( I );
|
||||
Value := Value / 1024.0;
|
||||
end;
|
||||
Result := Double2Str(Trunc(Value * 100) / 100); // fix by Oleg N. Cher:
|
||||
V := POS('.', Result); //
|
||||
if V > 0 then //
|
||||
Result[V] := ','; // .
|
||||
if I > 0 then
|
||||
Result := Result + Suffix[I];
|
||||
end;
|
||||
|
||||
{$IFDEF PAS_ONLY}
|
||||
function StrCopy(Dest, Source: PAnsiChar): PAnsiChar;
|
||||
var L: Integer;
|
||||
|
@ -429,88 +429,6 @@ asm
|
||||
POP EBP
|
||||
end;
|
||||
|
||||
function Num2Bytes( Value : Double ) : KOLString;
|
||||
asm PUSH EBX
|
||||
PUSH ESI
|
||||
PUSH EDI
|
||||
MOV EBX, ESP
|
||||
MOV ESI, EAX
|
||||
MOV ECX, 4
|
||||
MOV EDX, 'TGMk'
|
||||
@@1: FLD [Value]
|
||||
@@10: FICOM dword ptr [@@1024]
|
||||
FSTSW AX
|
||||
SAHF
|
||||
JB @@2
|
||||
FIDIV dword ptr [@@1024]
|
||||
FST [Value]
|
||||
WAIT
|
||||
TEST DL, 20h
|
||||
JE @@ror
|
||||
AND DL, not 20h
|
||||
JMP @@nxt
|
||||
@@1024: DD 1024
|
||||
@@100: DD 100
|
||||
@@ror: ROR EDX, 8
|
||||
@@nxt: LOOP @@10
|
||||
@@2: TEST DL, 20h
|
||||
JZ @@3
|
||||
MOV DL, 0
|
||||
@@3: MOV DH, 0
|
||||
PUSH DX
|
||||
MOV EDI, ESP
|
||||
FLD ST(0)
|
||||
CALL System.@TRUNC
|
||||
PUSH EDX
|
||||
PUSH EAX
|
||||
FILD qword ptr [ESP]
|
||||
POP EDX
|
||||
POP EDX
|
||||
MOV EDX, ESI
|
||||
CALL Int2Str
|
||||
FSUBP ST(1), ST
|
||||
FIMUL dword ptr [@@100]
|
||||
CALL System.@TRUNC
|
||||
TEST EAX, EAX
|
||||
JZ @@4
|
||||
XOR ECX, ECX
|
||||
MOV CL, 0Ah
|
||||
CDQ
|
||||
IDIV ECX
|
||||
TEST EDX, EDX
|
||||
JZ @@5
|
||||
MOV AH, DL
|
||||
SHL EAX, 16
|
||||
ADD EAX, '00. '
|
||||
PUSH EAX
|
||||
MOV EDI, ESP
|
||||
INC EDI
|
||||
JMP @@4
|
||||
@@5: SHL EAX, 8
|
||||
ADD AX, '0.'
|
||||
PUSH AX
|
||||
MOV EDI, ESP
|
||||
@@4: MOV EAX, [ESI]
|
||||
CALL System.@LStrLen
|
||||
ADD ESP, -100
|
||||
SUB EDI, EAX
|
||||
PUSH ESI
|
||||
PUSH EDI
|
||||
MOV ESI, [ESI]
|
||||
MOV ECX, EAX
|
||||
REP MOVSB
|
||||
POP EDX
|
||||
POP EAX
|
||||
{$IFDEF _D2009orHigher}
|
||||
XOR ECX, ECX // TODO: IDIV
|
||||
{$ENDIF}
|
||||
CALL System.@LStrFromPChar
|
||||
MOV ESP, EBX
|
||||
POP EDI
|
||||
POP ESI
|
||||
POP EBX
|
||||
end;
|
||||
|
||||
function S2Int( S: PKOLChar ): Integer;
|
||||
asm
|
||||
XCHG EDX, EAX
|
||||
|
Loading…
x
Reference in New Issue
Block a user