The problem is with floating point processors. This has been an issue since co-processors became available in the 80287 days. I don't know why they can't handle whole numbers, but I'm often adding 0.0000001 or something like that to ensure dates and times are correct. Sometimes 1/10/2005 00:00 (midnight) comes out as 30/09/2005 23:59:59, so I always add a small fraction to ensure at least the date is correct.
Ross. ----- Original Message ----- From: "Kyley Harris" <[EMAIL PROTECTED]> To: "NZ Borland Developers Group - Delphi List" <[email protected]> Sent: Sunday, October 23, 2005 7:25 PM Subject: [DUG] DateTime Floating Point Errors. I wonder if anyone else has noticed this irritating rounding issue on datetimes. Bear in mind that this is not a useful answer is you care about historical dates. I only care about dates greater than the year 2000. Problem. When comparing an "empty date" (meaning Date = 0.0) delphi behaves differently on different computers meaning that my if varDateValue = 0.0 can return false a lot of the time. This is also the same when comparing Dates that have a zero time factor. on my computer, EncodeDate(1899,12,30) + EncodeTime(0,0,0,0) does not return 0.0, but something along the lines of zero + an infintesimal fraction that does not equal zero any more. I solve my problem with the following method of forcing a date when setting a date property. if DateTimeValue < ZeroDateThreshold /* EncodeDate(1900,1,1) */ then begin result := 0.0; end else begin result := RecodeMilliSecond(result,0); end; This forces a removal of all these little tiny bits of rubbish on the end of my datetimes that occurs when I convert my string dates "yyyymmddhhnnsszzz" into real date etc. anyone got better ideas? if not.. hope this helps anyone else. -- Kyley Harris Harris Software +64-9-8455274 +64-21-671-821 _______________________________________________ Delphi mailing list [email protected] http://ns3.123.co.nz/mailman/listinfo/delphi _______________________________________________ Delphi mailing list [email protected] http://ns3.123.co.nz/mailman/listinfo/delphi
