delphi - Convert extended value to Time -


i want convert extended value time. before decimalseparator hours after decimalseparator minutes digital

8,62944444444444  --> 8:37 1,41666666666667  --> 1:25 

i've made funtion 1,41666666666667 --> 1:24 must 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 use exact 1,41666666666667 i'm 1:25 value must convert comes out soap enterface double (opostcalculationday.directassignedworktime).

the value 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 floating points

but best methode must use? roundto -14 because 1,41666666666667 14 numbers after separator of else?

my assumption values encoded this:

hours + minutes/60  

where hours , minutes integers , minutes between 0 , 59 inclusive.

you need round minutes rather truncate them

min := round(frac(avalue)*60); 

if fractional part contains seconds or milli-seconds need different calculation.

secs := round(frac(avalue)*3600); 

or

msecs := round(frac(avalue)*3600000); 

i don't see point in using extended here. type exists distinct double on x86 , in case slower double due poor alignment, , gives nothing here cannot double.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -