Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HourSpan not quite right

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
When calculating the difference between 9:00 am and 11:30 pm I would expect a HourSpan of 14.5, however I'm getting 14.51. Anyone know why I would get the extra .01 of an hour....Should I use the ROUND function to get an even 1/2 hour?

Almost all of the times will be on the hour or 1/2 hour, so the table should always have hour calculations of .0 or .5

Thanks,
Leslie
 
No, I should use the ROUNDTO function.....just a little more digging and you too can solve your own problems!

Thanks anyway!

Leslie
 
Personally, I would be bothered by a calculation that returned invalid info. Workarounds tend to bite you in the ars at some point. Test with the following...
Code:
procedure TForm1.Button1Click(Sender: TObject);
var
  begint, endt: TTime;
  n: double;
begin
  begint:= StrToTime(Edit1.Text);
  endt:= StrToTime(Edit2.Text);
  n:= HourSpan(begint, endt);
  Edit3.Text:= format('%f', [n]);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Edit1.Text:= '9:00 AM';
  Edit2.Text:= '11:30 PM';
  Edit3.Text:= '';
end;
... worked perfectly with no rounding. :)

Roo
Delphi Rules!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top