Skip to content
Advertisement

Calculate percent [closed]

I was wondering how to calculate the percentage in a level system, let me explain better: The user has his experience and this represents the level where the user is, i.e. if he has 0 experience he is level 1 and he needs 2000 experience for level 2.

Then I want to calculate the remaining percentage of how much is missing to reach 2000 experience.

Example:

JavaScript

I found an example on the internet where the user has 1,262 experience and needs 5000 for the next level so the percentage is 26.2%.

Advertisement

Answer

When performing calculations with real numbers, I would recommend to use double in case of Java.

If you need to be precise (for instance with money involved), I would handle the numbers after the decimal point myself.

In your case you could calculate it in the following way (remaining percentage):

JavaScript

If you want to calculate the percentage it currently has achieved it could be calculated this way:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement