Einzelnen Beitrag anzeigen

Benutzerbild von Uwe Raabe
Uwe Raabe

Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.058 Beiträge
 
Delphi 12 Athens
 
#5

AW: Format Extended mit Nullen

  Alt 9. Aug 2023, 11:29
Geht zumindest etwas schlanker.
Delphi-Quellcode:
function FormatFloat2(const AValue: Extended; const ADigits, ADecimals: Byte; const AFormatSettings: TFormatSettings): string;
begin
  var Fmt := string.Create('0', ADigits);
  var L := Fmt.Length - 3;
  while L > 1 do begin
    Insert(',', Fmt, L);
    Dec(L, 3);
  end;
  Fmt := Fmt + '.' + string.Create('0', ADecimals);
  Result := FormatFloat(Fmt, AValue, AFormatSettings);
end;
Edit: Das muss natürlich L > 1 heißen.
Uwe Raabe
Certified Delphi Master Developer
Embarcadero MVP
Blog: The Art of Delphi Programming

Geändert von Uwe Raabe ( 9. Aug 2023 um 11:42 Uhr) Grund: L > 1 statt 0
  Mit Zitat antworten Zitat