Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Formatierte Ausgabe mit Format()-Funktion (https://www.delphipraxis.net/73170-formatierte-ausgabe-mit-format-funktion.html)

madina 13. Jul 2006 08:38


Formatierte Ausgabe mit Format()-Funktion
 
Hallo,

wie konnte ich einen Double-VariablenInhalt so mit Format('%3.2f', Double) ausgeben, daß er Vorkomma 3 stellig und Nachkomma 2 Stellig ausgibt ?

mfg

Hawkeye219 13. Jul 2006 09:04

Re: Formatierte Ausgabe mit Format()-Funktion
 
Hallo madina,

beim Formatstring gibt die Zahl vor dem Punkt nicht die Anzahl der Stellen vor dem Komma sondern die Feldbreite an. Eine Stelle wird für den Dezimaltrenner benötigt:

Delphi-Quellcode:
Format('%6.2f', [Wert])
Bei negativen Werten <= -100 bzw. Absolutwerten >= 1000 werden auch mit dieser Formatangabe mehr als 3 Zeichen vor dem Komma ausgegeben.

Gruß Hawkeye

Hulig4n 13. Jul 2006 09:04

Re: Formatierte Ausgabe mit Format()-Funktion
 
FormatFloat

Delphi-Quellcode:
FormatFloat('000.00', 1.2);

RavenIV 13. Jul 2006 09:07

Re: Formatierte Ausgabe mit Format()-Funktion
 
Bei Delphi gibt es eine Hilfefunktion, bei der sehr gut erklärt wird.
Schreibe Format in deinen Quellcode, gehe mit dem Cursor auf Format und drücke F1.
Wenn er nachfragt, wählst Du "Format-Funktion" aus. Dort gibt es dann "Format-Strings".

Dort findest Du
Delphi-Quellcode:
Format('%8.2f', [123.456]);
Bei der Hilfe zu Format, gibt es auch Beispiele.
Kombinierst Du beide Informationen, dann kommst Du zu diesem Ergebnis:
Delphi-Quellcode:
Edit1.Text := Format('%6.2f', [Variablenname]);

go4hl80ve 27. Aug 2006 18:41

Re: Formatierte Ausgabe mit Format()-Funktion
 
klasse - damit klappt's :firejump:


Alle Zeitangaben in WEZ +1. Es ist jetzt 18:34 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz