Thema: Delphi Max. 3 Nachkommastellen

Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu
Online

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.170 Beiträge
 
Delphi 12 Athens
 
#8

Re: Max. 3 Nachkommastellen

  Alt 15. Jun 2009, 09:40
OK, hatte ich zwar noch nicht das Problem, aber dann einfach so ^^
Delphi-Quellcode:
Function MyFormat(f: Extended; Precession: Byte; Width: Byte = 0): String;
  Begin
    Result := Format('%*.*n', [Width, Precession, f]);
    If Pos(DecimalSeparator, Result) > 0 Then Begin
      While Result[Length(Result)] = '0do Delete(Result, Length(Result), 1);
      If Result[Length(Result)] = DecimalSeparator Then Delete(Result, Length(Result), 1);
    End;
  End;
oder
Delphi-Quellcode:
Function MyFormat(f: Extended; Precession: Byte; Width: Byte = 0): String;
  Var i: Integer;

  Begin
    Result := Format('%*.*n', [Width, Precession, f]);
    If Pos(DecimalSeparator, Result) > 0 Then Begin
      i := Length(Result);
      While Result[i] = '0do Dec Dec(i);
      If Result[i] = DecimalSeparator Then Dec(i);
      Result := Copy(Result, 1, i);
    End;
  End;
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat