Major int interacting with lesser float

So, I want a int to change a float value, but the int is bigger than the float value, just an example of what I have:

public int curArmor = 100;
public float armorFillBar = 1.0f;

The float is used to determinate how much the filler bar of the armor counter is visible, I can’t interact with the filler itself from the int, so I’ve to pass the value first to the float. How can I calculate the int to the float? Like if curArmor goes to 90, the float would be 0.9 and so on.

I can make it with if statements, but it would be just a dirty workaround.

Presumably you also have an int that defines your maxArmor.

There are other ways to get what you want, but the following should work:

armorFillBar = (float)curArmor / (float)maxArmor;

Optionally, if you know you will never need to use maxArmor in an int context, you could just make it a float to begin with, removing the need for the cast on maxArmor.

armorFillBar = (float)curArmor / maxArmor;