Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Rechnen (https://www.delphipraxis.net/72620-rechnen.html)

delphinia 4. Jul 2006 02:44


Rechnen
 
Habe Probleme mit der Komma rechnung

Das Problem ist zB::

das bei der Ausgabe
label_6.Caption := Format(const_6, [i1]);
Fehlerhaft werte Rauskommen - wegen diesem Komma ein wert zB bei 0,651452 wird mit 0 gerechnete Wichtig ist aber das auch mit den nachkommer gerechnet wird!


Mein Beispiel:
Delphi-Quellcode:
TIMER
var
  S1, ti1, ti2, ti3, i3b, i3c, i3d: string;
  i1, i2, i3a: Integer;

  f, f1, f2: Extended;
begin

  // AKTUELLE ZEIT IMMER ANZEIGEN
  label_3.Caption := Format(const_3, [FormatDateTime('dd.mm.yyyy', now), FormatDateTime('hh:mm:ss', now)]);
  now_timer.Interval := 1000;



 // Vergangene Zeit berechnen
  all_days := Abs(Now - Zeit1);
  ti1 := FormatDateTime('hh', Now - Zeit1);
  ti2 := FormatDateTime('nn', Now - Zeit1);
  ti3 := FormatDateTime('ss', Now - Zeit1);

  if Trunc(all_days) <= 0 then S1 := IntToStr(Trunc(all_days)) + ' Tage'
  else
    if Trunc(all_days) = 1 then S1 := IntToStr(Trunc(all_days)) + ' Tag'
    else
      if Trunc(all_days) > 1 then S1 := IntToStr(Trunc(all_days)) + ' Tage';

  label_4.Caption := Format(const_4, [S1]);
  label_5.Caption := Format(const_5, [ti1, ti2, ti3]);


  // PT
  i1 := Trunc(all_days) * 24 * 60;
  i1 := (StrToInt(ti1) * 60) + i1 + StrToInt(ti2);

  i1 := i1 div 60 div 24;
  i1 := i1 * StrToInt(UZigsTag);
  label_6.Caption := Format(const_6, [i1]);

  // UZ
  i2 := i1 div StrToInt(UZ);
  i2 := i2 * StrToInt(UC);
  label_7.Caption := Format(const_7, [i2]);


  // N UND T
  f := i1 * StrToFloat(UN);
  f1 := i1 * StrToFloat(UT);
  label_8.Caption := Format(const_8, [f, f1]);


  // Time
  i3a := i1 * StrToInt(Time); // Minunten gebraucht

  i3b := FormatDateTime('hh', i3a);
  i3c := FormatDateTime('nn', i3a);
  i3d := FormatDateTime('ss', i3a);

  label_9.Caption := Format(const_9, [i3b, i3c, i3d]);
end;

Kroko1999 4. Jul 2006 07:33

Re: Rechnen
 
(a) schau Dir mal folgende Funktionen an und Deine Quellen sollten einfacher und lesbarer werden:

DateTimeToString
DecodeTime

(b)wenn Du Integer nimmst wird es auch keine Nachkommastellen haben (Variable I1)!

oki 4. Jul 2006 07:37

Re: Rechnen
 
Hi delphinia,

ich möchte dir ja gerne helfen, verstehe aber deine Frage nicht so richtig.
1. gib mal "const_6" bekannt,
2. wo wird mit dem Label gerechnet?

Dann ist die aussage von Kroko auch nicht zu verachten. Mit Integer ist nicht viel im Nachkomma-Bereich.

Gruß oki


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:50 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