Hi All.
I have a float value, well actually its a single, that I need to convert to a time.
I write this function which turns the time as a string, but there is too much rounding going on.
i.e. a time that SHOULD be 1:18.526 ends up being 01:21.217 !!
I am sure there is a better way, or rather a way to make this function more precise therefore give me the righ time. Can someone help me out here?
Thanks,
function Return_Time(iTime : single):string;
var
totalET : single;
totalET_hours, totalET_Mins,totalET_secs, totalET_msecs : String;
begin
totalET:=iTime;
if Trunc(totalET) / 360 < 10 then
totalET_hours:='0'+inttostr(trunc(totalET) div 360)
else
totalET_hours:=inttostr(trunc(totalET) div 360);
if Trunc(totalET) / 60 < 10 then
totalET_Mins :='0'+inttostr(Trunc(totalET) div 60)
else
totalET_Mins :=inttostr(Trunc(totalET) div 60);
if Trunc(totalET) mod 60 < 10 then
totalET_secs := formatFloat('00', Ceil(totalET) mod 60)
else
totalET_secs := formatFloat('00', Ceil(totalET) mod 60);
Result:=totalET_hours+ ':' + totalET_mins + ':'+ totalET_Secs + '.' + Copy(FloatToStr(frac(totalET)),3,3);
end;
I have a float value, well actually its a single, that I need to convert to a time.
I write this function which turns the time as a string, but there is too much rounding going on.
i.e. a time that SHOULD be 1:18.526 ends up being 01:21.217 !!
I am sure there is a better way, or rather a way to make this function more precise therefore give me the righ time. Can someone help me out here?
Thanks,
function Return_Time(iTime : single):string;
var
totalET : single;
totalET_hours, totalET_Mins,totalET_secs, totalET_msecs : String;
begin
totalET:=iTime;
if Trunc(totalET) / 360 < 10 then
totalET_hours:='0'+inttostr(trunc(totalET) div 360)
else
totalET_hours:=inttostr(trunc(totalET) div 360);
if Trunc(totalET) / 60 < 10 then
totalET_Mins :='0'+inttostr(Trunc(totalET) div 60)
else
totalET_Mins :=inttostr(Trunc(totalET) div 60);
if Trunc(totalET) mod 60 < 10 then
totalET_secs := formatFloat('00', Ceil(totalET) mod 60)
else
totalET_secs := formatFloat('00', Ceil(totalET) mod 60);
Result:=totalET_hours+ ':' + totalET_mins + ':'+ totalET_Secs + '.' + Copy(FloatToStr(frac(totalET)),3,3);
end;
Cheers,
Jeremy
Coulter
------------------------------------------------------------------------
All email scanned with Nortons Antivurus
2002
------------------------------------------------------------------------