NeoMarine Posted April 29, 2008 Share Posted April 29, 2008 Hey people, I am rather silly and cannot solve this equation/math problem. I am displaying the level of a user. Here's how the experience goes for each level: Level 1 == 0-9999 EXP Level 2 == 10000-19999 EXP Level 3 == 20000-39999 Level 4 == 40000 EXP Where Level 4 is the final level... Now, on the screen I display XXX/XXXX EXP, where XXX = The Experience they have, and XXXX = the Experience they need to reach the next level Take this example, I am level 2 and have 12000 Experience, so on the screen it displays: 12000/40000 EXP Ok now for the problem area... I have a bar behind the text (12000/40000 EXP) where its width percentage is determined based on (12000/40000)*100 However, I need the bar to be using (0/40000)*100 BECAUSE when they are 10000/40000 for example, the bar is not displayed at the starting point (its at 10000/40000*100 percent!) I have tried to use ((12000-(last levels max -- in this case its 10000))/40000)*100, which makes the bar start at the right point... but as it gets more towards 39999/40000 it also takes away 10000 so it displays the width as 29999/40000*100 which is incorrect... see? Ok, I know it is complicated, hopefully someone understands what i'm trying to accomplish! I need the bar to display the width as if the exp at each level started at 0, where it really starts as the levels min amount... level 1 works fine... but everything after, the bar doesn't start from 0% width as I need it to! lol... please help! Link to comment https://forums.phpfreaks.com/topic/103434-math-equation-help/ Share on other sites More sharing options...
rhodesa Posted April 29, 2008 Share Posted April 29, 2008 min = the lower limit of level max = upper limit of level cur = current amount (cur - min)/(max - min) * 100 min = 10000 max = 19999 cur = 12000 (12000 - 10000)/(19999 - 10000) * 100 = 20% Link to comment https://forums.phpfreaks.com/topic/103434-math-equation-help/#findComment-529665 Share on other sites More sharing options...
sasa Posted April 29, 2008 Share Posted April 29, 2008 try <?php function get_my_level($e){ $levels = array(0,10000,20000,30000,40000); $max_level = count($levels) - 1; $level = $max_level; while ($levels[$level] > $e) $level--; if ($level == $max_level){ return array('level' => $level, 'next_level' => 'no next', 'precent' => 0); } $next_level = $levels[$level + 1]; $precent = ($e - $levels[$level]) / ($levels[$level + 1] - $levels[$level]) * 100; return array('level' => $level, 'next_level' => $next_level, 'precent' => $precent); } $level = get_my_level(919999); print_r($level); ?> Link to comment https://forums.phpfreaks.com/topic/103434-math-equation-help/#findComment-529683 Share on other sites More sharing options...
NeoMarine Posted April 29, 2008 Author Share Posted April 29, 2008 Thanks sasa, but I got my own function working with the equation rhodesa provided! Thank you!!!!!!!!!!!!!! :D Link to comment https://forums.phpfreaks.com/topic/103434-math-equation-help/#findComment-529693 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.