SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: Maths function problems.
-
Apr 24, 2006, 11:33 #1
- Join Date
- May 2004
- Location
- London
- Posts
- 46
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Maths function problems.
I have borrowed the following function from a phpBB MOD and want to use it elsewhere but cant get it working. The function is
PHP Code:function do_math($firstval, $value, $total)
{
$cst = ($firstval > 0) ? 90 / $firstval : 90;
if ($value != 0)
{
$percentage = ( $total ) ? round( min(100, ($value / $total) * 100)) : 0;
}
else
{
$percentage = 0;
}
$bar_percent = round($value * $cst);
}
PHP Code:$statistics = do_math('188', '22', '33');
print_r ($statistics)
-
Apr 24, 2006, 11:46 #2
- Join Date
- Apr 2006
- Posts
- 21
- Mentioned
- 3 Post(s)
- Tagged
- 0 Thread(s)
add this to the end of the function:
return array ($cst, $percentage, $bar_percent);
-
Apr 24, 2006, 11:48 #3
- Join Date
- Apr 2006
- Location
- UK
- Posts
- 29
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Why do you work out the variable $percentage, and then not do anything with it?
You should return something....
EDIT: Sorry - started reply when there were no others...
-
Apr 25, 2006, 04:20 #4
- Join Date
- May 2004
- Location
- London
- Posts
- 46
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by exam
Bookmarks