Calculating healthbar's value

In the my healthbar I have maxValue=632 and minValue=507.

It is X-coordinates. I need to transform it in to percents where:

  • 507 = 0%;
  • 632 = 100%;

And for that I need a formula to calculate it. Something like this:

healthText.text = " Health: " + (int)(currentHunger * 100 / 632);

Not sure what you’re asking… Maybe this helps:

void DisplayHealthText(float currrentHealth, float maxHealth = 100f, float minX = 507f, float maxX = 632f)
{
	float healthPercent = currrentHealth / maxHealth;
	healthText.text = " Health: " +  (healthPercent * (maxX - minX) + minX).ToString();
}