Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 12th, 2004, 4:43 PM   #1
stoodder
Newbie
 
Join Date: Jun 2004
Posts: 2
Rep Power: 0 stoodder is on a distinguished road
heyguys, well what im doing is working on a game currently, and what it has is something called ticks, what this does is liek every 5 minutes it updates the dataase and to reduce the amount of connections and queries to the database instead of changing certainfields.. for exampel that only run 20 "ticks" after you set somehting, i want to set a finish date, the only problem i run into is that the end date is usually right in between a tick... my plan now is to justround ot a number that is dividable by 300 in the unix time format.

hmm..
lol thats not that clear but for example if i had this is a time:

87587978

i would want to round that to the nearest number that is divisible by three hundred
lol if anyone has nay solution please reply

i thought of maybe using osmehting sorta liek
for($i = time;$i%300;$i++)
{
$endtime = $i
}

but that would be very bakc breaking sorta...
stoodder is offline   Reply With Quote
Old Jun 13th, 2004, 4:29 PM   #2
visualAd
Newbie
 
Join Date: Jun 2004
Location: Slough, UK
Posts: 3
Rep Power: 0 visualAd is on a distinguished road
Send a message via AIM to visualAd
Is this what you are looking for? You were right to use the % operator I wasn't quite sure what the for loop was for.
$number = 56873778;
$round_number = 300;
$middle = $round_number / 2;


if (($result = $number % $round_number) >= $middle)
 /* this number is greater than half the round amount
   therefore its rounded up */
 $number += $round_number - $result;
else
 /* this number is small than half the round amount
   therefore its rounded down */
 $number -= $result;
visualAd is offline   Reply With Quote
Old Jun 13th, 2004, 11:41 PM   #3
stoodder
Newbie
 
Join Date: Jun 2004
Posts: 2
Rep Power: 0 stoodder is on a distinguished road
lol nope your close, but what im saying is roudn it to the nearest number evenly divisable by 300 for example 2527254 would round down to 2527254, i think i figured a way around it though, what i plan on doing is just setting the current tick time then whenevr i enter somehting into the database ill just add 300 * 20(20 ticks) to the last tick time, i fyo know what i mean?
stoodder is offline   Reply With Quote
Old Jun 14th, 2004, 1:10 PM   #4
mesbaba8
Newbie
 
Join Date: Apr 2004
Posts: 1
Rep Power: 0 mesbaba8 is on a distinguished road
i will only give the algorithm, you try the code. There are two steps:

i) Last two digits should be 00 , so if it is >50 round to next hundred, and vica versa.

ii) sum all the digits of the new number, and continue this till you get one digit number (its easy with a recursive function). If the last digit, is divisible by 3, then it is ok, if not increase or decrease the hundred digit by one.

for example, take your number : 2527254

i) since last 2 digits > 50, round to 2527300

ii) sum of the digits = 19
sum of the digits = 10
sum of the digits = 1

then you will decrease the hundred digit by one.

so the final number is 2527200

not too diffucult to code
good luck
mesbaba8 is offline   Reply With Quote
Old Aug 10th, 2004, 11:16 PM   #5
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
Another way to do this, though less efficient.

(pseudo coded of course)
$an_integer= (int) $your_num / 300;
$new_val = $an_integer * 300; //this floors to nearest 300
if(( $your_num - $new_val ) >= 150 ) $new_val += 300;
__________________
Clifford Matthew Roche <geek@cliffordroche.com>
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:58 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC