# Finding next experience level using the square root?

I recently asked this question on how to calculate a level based on experience:

Algorithm for dynamically calculating a level based on experience points?

I am using the following calculation to determine the players level:

``````decimal experience = 1829;
decimal rawLevel = (decimal)(.06 * Math.Sqrt(experience));
decimal level = Math.Floor(rawLevel);
``````

For my test, `1829` experience points equates to `2.56600857364117M`, which I floor to level 2.

My question is, how can I figure out how many points it would take to get to the next level based off of the calculation above?

I know the next level is 3, so I would need to figure out how many points equate to level 3 so that I can find the difference. What formula would I use, given the constant .06 above?

Update: Solution:

``````int experience = 150777;
decimal rawLevel = (decimal)(.06 * Math.Sqrt(experience));
decimal level = Math.Floor(rawLevel);
decimal nextPoints = (decimal)Math.Pow((double)(level + 1) / 0.06, 2);
``````
-

You just need to do the inverse calculations in the inverse order :

``````Exp = (Level / 0.06)²
``````

So for level 2, you would need 1111 exp, and for level 3 you would need 2500.

I wrote a small piece of code to see the exp needed for certain levels : the rounding isn't great it's not very nice for a player to see 'Next Level : 64944 Exp'.

What you could do is use a litte trick to make your level exp more 'rounded', just divide and then multiply by 10.

Code Exmaple Here!

-
Awesome. Works perfect! – George Jun 17 '11 at 13:54