Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Round Rating to one decimal?

Quote Reply
Round Rating to one decimal?
Hi,

What would you recommend as a good way to change the rating value <%Rating%> to one decimal place?

As my LinksSQL sites currently in testing all the current values for sites listed there are 0.00 (default value).

Would it simply be a case of changing the Rating Column to one decimal which would require me to update the 200 or so links in LinksSQL?

or would it be possable with a Global, that is a working Global unlike the one below:

sub {
my $rating_value = $rec->{'Rating'};
my $rounded = round($rating_value);
return $rounded;
}

thanks.



Comedy Quotes - Glinks 3.3.0, PageBuilder, StaticURLtr, CAPTCHA, User_Edit_Profile

Quote Reply
Re: [Chas-a] Round Rating to one decimal? In reply to
You could use something like;

<%global_name($Rating)%>


Code:
sub {

my $Rating = shift;

if ($Rating eq "0.00") { return "0"; } else { return $Rating; }

}


That will show '0' for links that don't have a rating, and the full rating number if its something else (i.e. 4.50).

Is that what you are asking?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Round Rating to one decimal? In reply to
sprintf is best for rounding numbers.

Code:
my $rounded = sprintf("%.0f", $non_rounded);

If you were to use your method you should use

$Rating == 0.00

...instead of

$Rating eq "0.00"

Infact you can just do

$Rating == 0

..as 0 and 0.00 are the same thing.
Quote Reply
Re: [Mizuno] Round Rating to one decimal? In reply to
Sorry, I mis-read the question. Yeah, sprintf() would be better for changing it to 1 d.p ... I thought he wanted it to show '0' only if it was equal to "0.00".

BTW, the code $var eq "0.00" is the same as $var == "0.00" ... $Rating == 0.00 may even give you an ISE, as it isn't quoted... I'm probably wrong on that one though Tongue

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Round Rating to one decimal? In reply to
Thanks for your help guys :)

Here's what i've got so far:

# round_rating Global

sub {
my $non_rounded = $rec->('Rating');
my $rounded = sprintf("%.0f", $non_rounded);
return $rounded;
}

which im calling using Rating: <%round_rating%>

outputs> Rating: Unable to compile 'round_rating':



Comedy Quotes - Glinks 3.3.0, PageBuilder, StaticURLtr, CAPTCHA, User_Edit_Profile

Quote Reply
Re: [Chas-a] Round Rating to one decimal? In reply to
Quote:
my $non_rounded = $rec->('Rating');

This bit is wrong. It should be:

Code:
my $rec = shift;
my $non_rounded = $rec->{Rating};
Quote Reply
Re: [Mizuno] Round Rating to one decimal? In reply to
Thats the one, cheers!



Comedy Quotes - Glinks 3.3.0, PageBuilder, StaticURLtr, CAPTCHA, User_Edit_Profile

Quote Reply
Re: [Mizuno] Round Rating to one decimal? In reply to
... or, call it with;

Code:
<%round_rating($Rating)%>

... and then change;

Code:
my $non_rounded = $rec->('Rating');

to...

Code:
my $non_rounded = shift;

... which I think is faster, because you are only loading the variable, instead of the whole %ref.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Round Rating to one decimal? In reply to
The list of tags doesn't have to be loaded, it already exists in memory so there will be no speed difference.

It may even be quicker as the parser doesn't have to parse any custom arguments.

Last edited by:

Mizuno: Aug 30, 2003, 9:55 AM
Quote Reply
Re: [Mizuno] Round Rating to one decimal? In reply to
Ah well, either way... both the methods will work :p I don't have time to benchmark the globals Wink

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Round Rating to one decimal? In reply to
Cheers Andy Smile



Comedy Quotes - Glinks 3.3.0, PageBuilder, StaticURLtr, CAPTCHA, User_Edit_Profile