![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jun 2004
Posts: 2
Rep Power: 0
![]() |
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... |
|
|
|
|
|
#2 |
|
Newbie
|
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; |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jun 2004
Posts: 2
Rep Power: 0
![]() |
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?
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Apr 2004
Posts: 1
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#5 |
|
Expert Programmer
|
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|