Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.689 Beiträge
 
Delphi 11 Alexandria
 
#4

AW: Periodische Zahl runden

  Alt 30. Apr 2023, 20:34
Delphi-Quellcode:
function CutAtPeriod(const ADouble: Double; const AMinRepeating: Byte = 3): string;
var
  i, c: Integer;
  CutAt: Integer;
  s: string;
begin
  s := FloatToStrF(ADouble, ffFixed, 16, 16);
  Result := s;
  if Length(s) <= 3 then
    Exit;
  c := 0;
  CutAt := 0;
  for i := 3 to Pred(Length(s)) do
    begin
      if (s[Pred(i)] = s[i]) then
        Inc(c)
      else
        c := 0;
      if c >= AMinRepeating then
        begin
          CutAt := i;
          Break;
        end;
    end;
  if (CutAt > 0) then
    Result := Copy(s, 1, CutAt - AMinRepeating);
end;
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat