Gossamer Forum
Quote Reply
Average from 3 fields
Hey Everyone,

Andy will probably answer... But im putting this out there since maybe someone already has the answer.

I have 3 fields: field01 field02 field03.
Each can have values of: 0,1,2,3,4,5
I need to Add field01+field02+field03 and divide the result by 3.
The outcome should be a single number between 0 and 5.

This forum has a lot of great tips and tricks, globals and other stuff... I really with someone would delete all useless and wrong threads. Ive found many useless stuff looking for this answer which Im sure someone has asked and someone has answered... Just a thought...
Quote Reply
Re: [Gorospe] Average from 3 fields In reply to
Hi,

Something like this should do the trick:

get_average_value
Code:
sub {
return sprintf("%.0f", ($_[0]+$_[1]+$_[2]) / 3)
}
Call with:

Code:
<%get_average_value($field1,$field2,$field3)%>

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] Average from 3 fields In reply to
Heh.. Hi Andy...
Figured it was simple, didnt want to go straight to you knowing youre busy... :)
Thanks, worked like a charm.
Quote Reply
Re: [Gorospe] Average from 3 fields In reply to
No problem Angelic

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!