$start_minute= int( $start_second / 15 + 0.5 ) / 4;
-
tye
(but my friends call me "Tye") | [reply] [d/l] |
I think your logic is somewhat incorrect, nlafferty.
I haven't tested this, but it would appear that if $start_minute was, say 38, to begin with, you'd like to get the value .75, correct? The way your logic is set up, the first elsif will be true (38 >= 7.5), therefore $start_minute will be set to .25 and all logic ends. I doubt this is what you want.
One simple solution would be to change your code like so...
if ($start_minute < 7.5) {$start_minute = .0 ;}
elsif ($start_minute >= 7.5 && $start_minute < 22.5)
{$start_minute = .25 ;}
elsif ($start_minute >= 22.5 && $start_minute < 37.5)
{$start_minute = .5 ;}
elsif ($start_minute >= 37.5 && $start_minute < 52.5)
{$start_minute = .75 ;}
elsif ($start_minute >= 52.5) {$start_minute = 1.0 ;}
This should fix your problem. Now, if we look at the case where $start_minute is 38, none of these will be true until you get to the third elsif, which sets $start_minute to .75, which is, I believe, what you want.
Hopefully, this helps,
- Sherlock
Update: Doing conversions using just less thans or greater thans as BikeNomad and HyperZonk have done will make your code simpler but, please note, if you do that, order matters! My suggestion would be to do it that way, though.
Skepticism is the source of knowledge as much as knowledge is the source of skepticism. | [reply] [d/l] |
You are doing your comparisons sdrawkcab. You match anything
larger than 7.5 before you test for 22.5, so it never makes
it there. The logic you are using would work if you were
using sequential ifs instead of elsifs, but that is, of
course, not the best way to do it. You might try:
if ($startmin >= 52.5) { ... }
elsif ($startmin >= 37.5) { ... }
elsif ($startmin >= 22.5) { ... }
elsif ($startmin >= 7.5 ) { ... }
else { ... }
Update: ... and of course, bikeNomad's
method will work, also reversing the test and the order.
(That rat got in before me! :)
-HZ | [reply] [d/l] |
It's not clear what you're trying to produce here, but if you're trying to detect ranges, you could do this: if ($start_minute < 7.5) {$start_minute = .0 ;}
elsif ($start_minute < 22.5) {$start_minute = .25 ;}
elsif ($start_minute < 37.5) {$start_minute = .5 ;}
elsif ($start_minute < 52.5) {$start_minute = .75 ;}
else {$start_minute = 1.0}
| [reply] [d/l] |
I'm actually tring to round my values from a time value to the nearest 15 minutes. Then convert it to a decimal. Thanks, I'll give your example a shot
| [reply] |
my $rounded = int ( $value / 15 + 0.5 ) / 4;
-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
| [reply] [d/l] |
This works, but with your >= becoming > and < becoming <=
$start_minute = int(($start_minute + 7.5)/15)/4;
Let's break this down:
$start_minute + 7.5 # add 7.5 mins to number
/15 # which quarter is the minute in?
int() # ...0,1,2,3 or 4?
/4 # to get desired result
cLive ;-)
Update: oops, tye beat me to it (in a slightly different, but effectively the same, way)... :) | [reply] [d/l] [select] |