Truncating Output to 1 Decimal Position

  • Thread starter edisonl via AccessMonster.com
  • Start date
E

edisonl via AccessMonster.com

Hi,

I have a function that performs calculation of time difference using
timediff = cint(timediff);
timediff = datediff ("n", starttime, endtime)/60;
timediff = cdec(timediff);

'What I like to achieve is retrieve answer in round down to half hourly.
either 0.5 or whole number
Eg: 5.4 ~ 5, 1.5, 2, 2.5 etc..etc..

Regards & God Bless, Edison
 
J

John W. Vinson

Hi,

I have a function that performs calculation of time difference using
timediff = cint(timediff);

What's the point of the above line, since you're overwriting the value
immediately with the next line???
timediff = datediff ("n", starttime, endtime)/60;
timediff = cdec(timediff);

'What I like to achieve is retrieve answer in round down to half hourly.
either 0.5 or whole number
Eg: 5.4 ~ 5, 1.5, 2, 2.5 etc..etc..

To round DOWN (i.e. 1 hour 59 minutes becomes 1.5) use integer divide to get
thirty-minute intervals:

(DateDiff("n", [starttime], [endtime]) \ 30) /2.


Note that this will give 0 for any value under 30 minutes, but that's what is
meant by "round down".
 
E

edisonl via AccessMonster.com

Hi Vinson,

Thanks for replying . . I tried:

But it seems quite impossible to retrieve the value..
Eg: starttime=05/04/09 16:15, endtime=05/04/09 17:45

i did a >> starttime = cdate(starttime), endtime=cdate(endtime)
then starttime = mid(starttime,10,6), endtime = mid(endtime,10,6)

msgbox starttime & " " & endtime 'to double check the starttime & endtime
value

totalhours = CDec(totalhours)
totalhours = (DateDiff("n", starttime, endtime) \ 30) / 2
totalhours = CDec(totalhours)

MsgBox "Totalhours:" & totalhours 'Right Value:1.5 but I gotten the output as
2 ! *Duh ?

Regards & God Bless, Edison
 
J

John W. Vinson

Hi Vinson,

Thanks for replying . . I tried:

But it seems quite impossible to retrieve the value..
Eg: starttime=05/04/09 16:15, endtime=05/04/09 17:4


Where are these? Table fields, form controls, what? If table fields, what's
the datatype?
i did a >> starttime = cdate(starttime), endtime=cdate(endtime)
then starttime = mid(starttime,10,6), endtime = mid(endtime,10,6)

msgbox starttime & " " & endtime 'to double check the starttime & endtime
value

totalhours = CDec(totalhours)
totalhours = (DateDiff("n", starttime, endtime) \ 30) / 2
totalhours = CDec(totalhours)

MsgBox "Totalhours:" & totalhours 'Right Value:1.5 but I gotten the output as
2 ! *Duh ?

The code, of course, bears no resemblance whatsoever to what I posted. What's
the Dim statement for Totalhours, or what's its datatype if it's a table
field?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top