General information
Category:
Coding, syntax & commands
Title:
FoxPro and Divsion with Date Time Fields
I'm using datetime fields to store the start and end time for an employee shift. I've discovered inconsistent results when calculating the time span on the shift.
I'm calculating the elapsed time as follows (((EndTime - StartTime) / 60) /60) and appears to work with the following exception.
In my example, the start time is 02/11/2002 09:00:00 PM and end time is 02/12/2002 07:00:00 AM which represents 10 hours of work. If the set decimals command is set to 2 the result displayed is 10.00 but when the field is tested or compared to another value FoxPro sees the result as 9.99999999627471. I discovered this by setting the set decimals command to 18, the max number of decimals allowed. I discovered this problem while testing the total time an employee worked to 40.00, this shift brought the employee time to 40 hours and if the statement would fail. The system is seeing the total time worked as 39.99999....
Below are the results I receive from the command window with set decimals to 18 and execute each step by itself:
EndTime - StartTime = 36000 && number of seconds in span
((EndTime - StarTime) / 60) = 599.99999977648260 && Number of Minutes - it shoud by 600???
(((EndTime - StartTime) / 60) / 60) = 9.99999999627471
I don't understand why dividing 36000 by 60 returns anything other than 600. I can solve this problem by adding a ROUND() command but I concerned this error will show up some place else. Is this a know problem? If so what are the recommended work arounds?
TIA
Gary
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only