Skip to content
Advertisement

Get the percentage of a value between two values

I have a minimum value and a maximum value (The values can change). I also have a value that is in between of these two values.

private int minValue = 201;
private int maxValue = 500;
private int currentValue = 482

Now I need to get the percentage of the currentValue between 0% and 100%. Is this even possible?

Thank you for your help!

Advertisement

Answer

I think what you want to have is this calculation:

double percentage = (currentValue - minValue) / (maxValue - minValue);

Just like @kevin-esche wrote in the comments.

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