C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Rounding time algo

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Marcus
Guest





PostPosted: Thu Sep 14, 2006 9:10 am    Post subject: Rounding time algo Reply with quote



Hi, was wondering if anyone knows a good algo for rounding time to a
desired interval.

For instance, I have data set that is timestamped in second resolution
and I need to modify that data to be timestamped for an x minute
interval. So if time t = 93601, and x = 5 then t would be rounded up
to 94000... if x were 1, t would equal 93700, etc. All time is integer
based.

Any help would be really appreciated.

Marcus
Back to top
Mark P
Guest





PostPosted: Thu Sep 14, 2006 9:10 am    Post subject: Re: Rounding time algo Reply with quote



Marcus wrote:
Quote:
Hi, was wondering if anyone knows a good algo for rounding time to a
desired interval.

For instance, I have data set that is timestamped in second resolution
and I need to modify that data to be timestamped for an x minute
interval. So if time t = 93601, and x = 5 then t would be rounded up
to 94000... if x were 1, t would equal 93700, etc. All time is integer
based.

Any help would be really appreciated.

Marcus


I don't understand your math. If x = 5 and you want to round to 5
minute intervals, then a value t in seconds should be a multiple of 5 *
60 = 300 seconds. But 94000 is not divisible by 300. It looks like
you're assuming 100 seconds per minute based on your rounded values.

In any event, we can phrase this as a more general question: how do you
round a value n to a multiple of m? Since it looks like you want to
round up, you can do the following:

int remainder = n % m;
int rounded_n = n + (remainder ? (m - remainder) : 0);
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.