Thema: Delphi Problem mit floattostrf

Einzelnen Beitrag anzeigen

Benutzerbild von Nothine
Nothine

Registriert seit: 3. Jul 2004
Ort: Mülheim an der Ruhr
198 Beiträge
 
Delphi 5 Enterprise
 
#6

Re: Problem mit floattostrf

  Alt 27. Nov 2004, 13:10
du könntest Delphi-Referenz durchsuchenFormatFloat benutzen, und eine abfrage erstellen, ob es eine ganze zahl ist, z.B. so:
Delphi-Quellcode:
var A,B: Extended;
const Frmt: array[Boolean] of string[5] = ('#','#.000');

// A := 3;
// B := 5.3;
  Edit1.Text := FormatFloat( Frmt[Frac(A*B) <> 0] , A*B );

{bzw.}

if Frac(A*B) <> 0 then
  Edit1.Text := FormatFloat('#.000',A*B) //alle vorkomma-stellen, 3 nachkomma-stellen
else Edit1.Text := FormatFloat('#',A*B); //nur vorkomma-stellen
if ThisPost is senseless then
ThisPost.WasPostedBy := SomeoneElse();
  Mit Zitat antworten Zitat