mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
FIX: IntToStrTS when ThousandSeparator is NUL (#1738)
also simplify IntToStrTS (smaller, less variables)
This commit is contained in:
parent
5b42d8637c
commit
e73b33791b
1 changed files with 25 additions and 26 deletions
|
|
@ -388,33 +388,32 @@ begin
|
|||
end;
|
||||
|
||||
function IntToStrTS(const APositiveValue: Int64): String;
|
||||
var i, vSrcLen, vSrcI, vSrcNumberNo, vResLen: byte;
|
||||
var
|
||||
// 25 is length of '9,223,372,036,854,775,807' (max Int64 with thousand separators)
|
||||
ShortStringResult: String[25];
|
||||
SmallI, BigI: Byte;
|
||||
begin
|
||||
if APositiveValue < 0 then
|
||||
Exit(IntToStr(APositiveValue));
|
||||
Str(APositiveValue, Result);
|
||||
vSrcLen := Result.Length;
|
||||
|
||||
vResLen := vSrcLen + ((vSrcLen - 1) div 3);
|
||||
if vSrcLen = vResLen then
|
||||
Exit;
|
||||
|
||||
SetLength(Result, vResLen);
|
||||
|
||||
vSrcI := vResLen;
|
||||
vSrcNumberNo := 1;
|
||||
|
||||
for i:= vSrcLen downto 1 do
|
||||
begin
|
||||
Result[vSrcI] := Result[i];
|
||||
Dec(vSrcI);
|
||||
if(vSrcNumberNo <> vSrcLen) and (vSrcNumberNo mod 3 = 0) then
|
||||
begin
|
||||
Result[vSrcI] := FormatSettings.ThousandSeparator;
|
||||
Dec(vSrcI);
|
||||
end;
|
||||
Inc(vSrcNumberNo);
|
||||
end;
|
||||
Str(APositiveValue, ShortStringResult);
|
||||
if (APositiveValue > 999) and (DefaultFormatSettings.ThousandSeparator <> #0) then
|
||||
begin
|
||||
SmallI := Length(ShortStringResult);
|
||||
BigI := SmallI + (SmallI - 1) div 3;
|
||||
SetLength(ShortStringResult, BigI);
|
||||
repeat
|
||||
ShortStringResult[BigI] := ShortStringResult[SmallI];
|
||||
Dec(BigI);
|
||||
Dec(SmallI);
|
||||
ShortStringResult[BigI] := ShortStringResult[SmallI];
|
||||
Dec(BigI);
|
||||
Dec(SmallI);
|
||||
ShortStringResult[BigI] := ShortStringResult[SmallI];
|
||||
Dec(BigI);
|
||||
Dec(SmallI);
|
||||
ShortStringResult[BigI] := DefaultFormatSettings.ThousandSeparator;
|
||||
Dec(BigI);
|
||||
until BigI = SmallI;
|
||||
end;
|
||||
Result := ShortStringResult;
|
||||
end;
|
||||
|
||||
function cnvFormatFileSize(const iSize: int64; FSF: TFileSizeFormat; const Number: integer): string;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue