Jump to content

Math Equation... help?


NeoMarine

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.