Announcement

Collapse
No announcement yet.

TLabel->Caption

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • TLabel->Caption

    <body bgcolor=#FFFFFF text=#000000>
    <code>
    Ich&nbsp;verzweifle&nbsp;bald,&nbsp;denn&nbsp;ich& nbsp;kann&nbsp;nirgends&nbsp;Hilfe&nbsp;dafür&nbsp ;finden,&nbsp;<br>
    wie&nbsp;man&nbsp;einen&nbsp;Gleitkommawert&nbsp;z ur&nbsp;Anzeige&nbsp;bringt.<br>
    <br>
    Was&nbsp;muß&nbsp;ich&nbsp;machen&nbsp;um&nbsp;ein en&nbsp;Interwert,&nbsp;den&nbsp;ich&nbsp;dividier e&nbsp;als<br>
    Zahl&nbsp;mit&nbsp;einer&nbsp;Kommastelle&nbsp;anz eigen&nbsp;zu&nbsp;lassen.&nbsp;Z.&nbsp;B.:<br>
    <br>
    &nbsp;&nbsp;<font color=#000000><b>int</b></font>&nbsp;<font color=#0000A0><b>354509</b></font>/<font color=#0000A0><b>1000000</b></font>&nbsp;=&nbsp;<font color=#0000A0><b>0</b></font>,<font color=#0000A0><b>354509</b></font><br>
    &nbsp;&nbsp;Label1->Caption&nbsp;=&nbsp;<font color=#0000A0><b>0</b></font>,<font color=#0000A0><b>354509</b></font><br>
    <br>
    Ich&nbsp;weiß,&nbsp;der&nbsp;Syntax&nbsp;stimmt&nb sp;hier&nbsp;nicht.&nbsp;Das&nbsp;war&nbsp;eher<br >
    symbolisch&nbsp;gemeint.&nbsp;Aber&nbsp;gibt&nbsp; es&nbsp;dafür&nbsp;eine&nbsp;Möglichkeit?<br>
    <br>
    Ich&nbsp;wäre&nbsp;euch&nbsp;sehr&nbsp;dankbar.<br >
    <br>
    Gruß&nbsp;Roman<br>
    </code>
    </body>

  • #2
    Hallo Roman

    Das Problem ist, dass du wenn du zwei Integer-Zahlen dividierst eine Ganzzahlendivision ausführst. Also zum Beispiel 45/16 gibt 2. Der Rest wird abgeschnitten. Wenn du 45%15 (Modula) rechnest bekommst du den Rest.
    In deinem Fall willst du aber eine Float-Zahl erhalten. Damit du das bekommst musst du mindestens eine der beiden Zahlen vor der Division in float umwandlen.
    Beispiel:<br><br>

    int Zahl1=45;<br>
    int Zahl2=16;<br>
    float Ergebnis=float(Zahl1)/float(Zahl2); //Beide Zahlen werden in float umgewandelt.<br>
    Label1->Caption=Ergebnis;<br><br>

    Du kannst auch direkt das Ergebnis dem Label zuordnen:<br>
    Label1->Caption=float(Zahl1)/float(Zahl2);<br><br>

    Gruss<br>
    Marco Vergar

    Comment


    • #3
      Hallo Marco,

      Danke für Deine Hilfe. Kannst Du mir vielleicht auch noch sagen, was ich machen muß, um eine Zahl nur mit 2 Nachkommastellen anzuzeigen.

      z. B.: 0,35

      Und kann man in einem GUI-Programm auch irgendwie die Funktion printf zum Einsatz bringen?

      Gruß Roma

      Comment


      • #4
        <html>

        <head>
        <meta http-equiv="Content-Type"
        content="text/html; charset=iso-8859-1">
        <meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
        <title>Normale Seite ohne Titel</title>
        </head>

        <body bgcolor="#FFFFFF">

        <p>Hallo Roman, das hier sollte funktionieren. Ob es noch
        &quot;in&quot; ist, weiß ich nicht.<br>
        <br>
        char Text[20];<br>
        sprintf(Text,&quot;%.2f&quot;,float(Zahl1)/float(Zahl2));<br>
        Label1-&gt;Caption=Text;<br>
        </p>

        <p>Gruß - Günther<br>
        <br>
        </p>
        </body>
        </html&gt
        Günther

        Comment


        • #5
          Danke Günther

          Ob es "in" ist oder nicht, ist mir egal. Hauptsache es funktioniert

          Comment


          • #6
            Hallo Roman,
            Versuch mal das.....

            Label1->Caption = FormatFloat("####0.00",deinfloat);

            Gruß Ing

            Comment


            • #7
              Danke Ingo für deinen Tip. Ich werde diesen bald einmal ausführen bzw. ausprobieren.

              Gruß Roma

              Comment

              Working...
              X