Round numbers to the nearest 5?

Forum for users that want to write their own custom queries against the PT database either via the Structured Query Language (SQL) or using the PT3 custom stats/reports interface.

Moderator: Moderators

Round numbers to the nearest 5?

Postby mager » Thu Mar 15, 2012 1:14 pm

I'm want to add format expression to few stat that will round the number to the nearest 5 - so it will round to 5,10,15,20 etc(for example 12 will become 10, 14 will become 15, 18 will become 20).
Is there an easy way to do it? Can you give me an example of how to do it for RFI stat?

Thank...
mager
 
Posts: 180
Joined: Thu Sep 17, 2009 7:04 pm

Re: Round numbers to the nearest 5?

Postby kraada » Thu Mar 15, 2012 5:03 pm

I'm not aware of a simple way to do this I'm afraid.
kraada
Moderator
 
Posts: 54430
Joined: Wed Mar 05, 2008 2:32 am
Location: NY

Re: Round numbers to the nearest 5?

Postby mager » Thu Mar 15, 2012 5:48 pm

kraada wrote:I'm not aware of a simple way to do this I'm afraid.


So in order to achieve this, I need to enter all of this format expression for each stat:
Code: Select all
if( ((this) >2.5 AND (this) =< 7.5), '5', format_number((this), 0, false, false) )
if( ((this) >7.5 AND (this) =< 12.5), '10', format_number((this), 0, false, false) )
if( ((this) >12.5 AND (this) =< 17.5), '15', format_number((this), 0, false, false) )
if( ((this) >17.5 AND (this) =< 22.5), '20', format_number((this), 0, false, false) )
if( ((this) >22.5 AND (this) =< 27.5), '25', format_number((this), 0, false, false) )
if( ((this) >27.5 AND (this) =< 32.5), '30', format_number((this), 0, false, false) )
if( ((this) >32.5 AND (this) =< 37.5), '35', format_number((this), 0, false, false) )
if( ((this) >37.5 AND (this) =< 42.5), '40', format_number((this), 0, false, false) )
if( ((this) >42.5 AND (this) =< 47.5), '45', format_number((this), 0, false, false) )
if( ((this) >47.5 AND (this) =< 52.5), '50', format_number((this), 0, false, false) )
if( ((this) >52.5 AND (this) =< 57.5), '55', format_number((this), 0, false, false) )
if( ((this) >57.5 AND (this) =< 62.5), '60', format_number((this), 0, false, false) )
if( ((this) >62.5 AND (this) =< 67.5), '65', format_number((this), 0, false, false) )
if( ((this) >67.5 AND (this) =< 72.5), '70', format_number((this), 0, false, false) )
if( ((this) >72.5 AND (this) =< 77.5), '75', format_number((this), 0, false, false) )
if( ((this) >77.5 AND (this) =< 82.5), '80', format_number((this), 0, false, false) )
if( ((this) >82.5 AND (this) =< 87.5), '85', format_number((this), 0, false, false) )
if( ((this) >87.5 AND (this) =< 92.5), '90', format_number((this), 0, false, false) )
if( ((this) >92.5 AND (this) =< 97.5), '95', format_number((this), 0, false, false) )


With "," between each "if"? Is that correct?
Wouldn't that cause some kind of overload or something like that having few stats like this on my HUD? (overload which might cause any kind of problem)

Thanks
mager
 
Posts: 180
Joined: Thu Sep 17, 2009 7:04 pm

Re: Round numbers to the nearest 5?

Postby kraada » Thu Mar 15, 2012 5:56 pm

Actually I think you want:

if( this <= 2.5, '0', if( this =< 7.5), '5', if( (this) =< 12.5), '10', if( (this) =< 17.5), '15', .... if (this <= 97.5, '95', '100')) ... )

Otherwise you'll hit that first else and you'll just get to see the value of the stat. You can format the '0', '5', etc using format number if you want as format_number( 5, 0, false, false) if you prefer.
kraada
Moderator
 
Posts: 54430
Joined: Wed Mar 05, 2008 2:32 am
Location: NY

Re: Round numbers to the nearest 5?

Postby mager » Thu Mar 15, 2012 7:52 pm

kraada wrote:Actually I think you want:

if( this <= 2.5, '0', if( this =< 7.5), '5', if( (this) =< 12.5), '10', if( (this) =< 17.5), '15', .... if (this <= 97.5, '95', '100')) ... )

Otherwise you'll hit that first else and you'll just get to see the value of the stat. You can format the '0', '5', etc using format number if you want as format_number( 5, 0, false, false) if you prefer.


OK so my full format expression, including other parts I have will look like this:
Code: Select all
if ( (this) > 99.5, '99', (format( '{1}{2}', if ( (this) < 9.5, ' ', ''), format_number( (this), 0, false, false) ) )), if( cnt_p_open_opp = 0, ' - ', format_number((this), 0, false, false) ), if( ((this) >= 2.5 AND (this) =< 7.5)), '5', if( (this) =< 12.5), '10', if( (this) =< 17.5), '15', .... if ((this) <= 97.5, '95') )


(in this way, the round to the nearest 5 exclude the numbers 1,2,98,99 - everything else, will be rounded to the nearest 5)
Will that work? Also, that's a lot of coding. Will having few of these on my HUD have the potential of causing some problems/slow downs/etc?

Thanks.
mager
 
Posts: 180
Joined: Thu Sep 17, 2009 7:04 pm

Re: Round numbers to the nearest 5?

Postby mager » Fri Mar 16, 2012 11:39 am

mager wrote:
kraada wrote:Actually I think you want:

if( this <= 2.5, '0', if( this =< 7.5), '5', if( (this) =< 12.5), '10', if( (this) =< 17.5), '15', .... if (this <= 97.5, '95', '100')) ... )

Otherwise you'll hit that first else and you'll just get to see the value of the stat. You can format the '0', '5', etc using format number if you want as format_number( 5, 0, false, false) if you prefer.


OK so my full format expression, including other parts I have will look like this:
Code: Select all
if ( (this) > 99.5, '99', (format( '{1}{2}', if ( (this) < 9.5, ' ', ''), format_number( (this), 0, false, false) ) )), if( cnt_p_open_opp = 0, ' - ', format_number((this), 0, false, false) ), if( ((this) >= 2.5 AND (this) =< 7.5)), '5', if( (this) =< 12.5), '10', if( (this) =< 17.5), '15', .... if ((this) <= 97.5, '95') )


(in this way, the round to the nearest 5 exclude the numbers 1,2,98,99 - everything else, will be rounded to the nearest 5)
Will that work? Also, that's a lot of coding. Will having few of these on my HUD have the potential of causing some problems/slow downs/etc?

Thanks.


1. If you can confirm if that will be workable format expression it will be nice:
As I said, I want it to round the number to the nearest 5(except 1,2,88,99), I want it to make 100 number to 99, I want it to make the 'box size' fixed(based on two digits) and I want no opportunity to be seen as what I define(I use format expression for it because I use different colors in the HUD and I want the no opportunity to be in the same color, not in one color for all no opportunities). Will the above format expression do it all?

2. It's pretty complex coding. Will having few of these on my HUD have the potential of causing some problems/slow downs/etc?

Thanks
(I hope I do not nag too much - iv'e seen that you already had the 'round' of reply's without answering this. It's a lot of work to do and I want to make sure it is correct so I won't have to do it twice)
mager
 
Posts: 180
Joined: Thu Sep 17, 2009 7:04 pm

Re: Round numbers to the nearest 5?

Postby WhiteRider » Sat Mar 17, 2012 1:10 pm

That should work fine - personally I'd just do a couple of cases first and check that it's working before doing the whole set.
It shouldn't cause any delays - it will only need to read the information from the database once and that is the bottleneck.
WhiteRider
Moderator
 
Posts: 54025
Joined: Sat Jan 19, 2008 7:06 pm
Location: UK


Return to Custom Stats, Reports, and SQL [Read Only]

Who is online

Users browsing this forum: No registered users and 14 guests