Raised This Month: $51 Target: $400
 12% 

PowerOfFive


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 02-23-2014 , 06:09   PowerOfFive
Reply With Quote #1

Does anyone happen to have a handy stock that will convert numbers like

1 to 0
and 3 to 5

so it would be

0
5
10
15
20
etc..

I would apprecciate it
Pelipoika is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 02-23-2014 , 06:17   Re: PowerOfFive
Reply With Quote #2

I think you mean 2 to 5, right?

new output = (input*5)-5;

It would be better if you kept 0 as 0, changing 1 to 5, 2 to 10, 3 to 15, etc. This depends on your purposes though.

new output = (input*5);

This seems WAY too simple though; I've probably misunderstood your question.
__________________
ddhoward is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 02-23-2014 , 06:26   Re: PowerOfFive
Reply With Quote #3

Quote:
Originally Posted by ddhoward View Post
I think you mean 2 to 5, right?

new output = (input*5)-5;

It would be better if you kept 0 as 0, changing 1 to 5, 2 to 10, 3 to 15, etc. This depends on your purposes though.

new output = (input*5);

This seems WAY too simple though; I've probably misunderstood your question.
PHP Code:
    new raw GetRandomInt(2,56);
    
PrintToChat(client"Raw = %i"raw);
    new 
output = (raw*5)-5;
    
PrintToChat(client"Output = %i"output); 
Raw = 49
Output = 240

Output should of have been 50 after conversion

Last edited by Pelipoika; 02-23-2014 at 06:42.
Pelipoika is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 02-23-2014 , 06:29   Re: PowerOfFive
Reply With Quote #4

What the heck.
I just didn't get it at all.
__________________
Leonardo is offline
Oshizu
Veteran Member
Join Date: Nov 2012
Location: Warsaw
Old 02-23-2014 , 06:32   Re: PowerOfFive
Reply With Quote #5

Neither do i
__________________
...
Oshizu is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 02-23-2014 , 06:35   Re: PowerOfFive
Reply With Quote #6

Basically i want numbers that can be divided by 5
Pelipoika is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 02-23-2014 , 06:52   Re: PowerOfFive
Reply With Quote #7

Quote:
Originally Posted by Pelipoika View Post
Basically i want numbers that can be divided by 5
But HOW do you want those numbers? Your first post indicated that you wanted each regular integer to have a corresponding multiple of 5. 1 = 0, 2 = 5, 3 = 10, 4 = 15, 5 = 20, 6 = 25, etc.

Or is this not what you want?
__________________
ddhoward is offline
Cookies.net
Senior Member
Join Date: Jan 2011
Old 02-23-2014 , 06:59   Re: PowerOfFive
Reply With Quote #8

Sounds like you want to round to nearest fifth, so maybe something like

PHP Code:
// For integers
new output = ((input 5) / 5) * 5;

// For floats
new Float:output RoundToNearest(input 5.0) * 5.0
It can be changed to any number as long as you change the 5's or 5.0's to something else (must be the same in all instances)
Cookies.net is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 02-23-2014 , 07:00   Re: PowerOfFive
Reply With Quote #9

Quote:
Originally Posted by ddhoward View Post
But HOW do you want those numbers? Your first post indicated that you wanted each regular integer to have a corresponding multiple of 5. 1 = 0, 2 = 5, 3 = 10, 4 = 15, 5 = 20, 6 = 25, etc.

Or is this not what you want?
I don't want them to have any corresponding multiples
I want the number to round down or up according to what the number is

3 rounds up to 5
5 stays as 5
6 rounds down to 5
7 rounds down to 5
8 rounds up to 10
9 rounds up to 10
10 stays as 10

I can't really explain it any better

EDIT:

Will try your replies Cookies.net and KissLick

Last edited by Pelipoika; 02-23-2014 at 07:02.
Pelipoika is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 02-23-2014 , 07:03   Re: PowerOfFive
Reply With Quote #10

It would be easier to use the modulo function, methinks.

PHP Code:
stock RoundToFive(input) {
    new 
remainder input 5;
    if (
remainder == 0) return input;
    if (
remainder <= 2) return (input-remainder);
    if (
remainder >= 3) return (input+(5-remainder));

__________________

Last edited by ddhoward; 02-23-2014 at 07:07.
ddhoward is offline
Reply



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


All times are GMT -4. The time now is 20:26.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode