I want to convert a extended value to time. before the DecimalSeparator is hours after the decimalseparator are minutes digital
8,62944444444444 --> 8:37
1,41666666666667 --> 1:25
I've made this funtion but I get for 1,41666666666667 --> 1:24 It must be 25 minutes
function MyConvertion(AValue: Extended): TDateTime;
var
Hour, Min, Sec, MSec: Word;
begin
Hour:= Trunc(AValue);
Min:= Trunc(Frac(AValue)*60);
result:= EncodeTime(Hour, Min, 0, 0);
end;
When I use exact 1,41666666666667 I'm get 1:25 But the value I must convert comes out from a soap enterface as double (oPostCalculationDay.DirectAssignedWorkTime).
The value I get in debug mode = 1,41666666666667
MyConvertion(1,41666666666667) --> 1:25
MyConvertion(oPostCalculationDay.DirectAssignedWorkTime) --> 1:24
MyConvertion(RoundTo(oPostCalculationDay.DirectAssignedWorkTime, -15)) --> 1:25
MyConvertion(RoundTo(oPostCalculationDay.DirectAssignedWorkTime, -16)) --> 1:24
MyConvertion(strtofloat(floattostr(oPostCalculationDay.DirectAssignedWorkTime)))--> 1:25
I'm thinking is something like Floating points
But what is the best methode I must use? Roundto -14 because 1,41666666666667 is 14 numbers after the separator of something else?
My assumption is that the values are encoded like this:
where
HoursandMinutesare integers andMinutesis between 0 and 59 inclusive.You need to round the minutes rather than truncate them
If the fractional part contains seconds or even milli-seconds then you need a different calculation.
or
I don't see much point in using extended here. That type only exists distinct from double on x86 and in any case is slower than double due to poor alignment, and gives you nothing here that you cannot get from double.