# Rounding up Damage to an Int

Hey, I have a health script which allows the player to take Damage via RPC. I also have an Armor system, but this system sometimes spits out decimals as a result. I was wondering if I could round Health so that no decimals are created?
(Note: Just ignore MyPlayer. if its just confusing you. It doesn’t really mean anything special.)

``````//If this function is triggered, subtract the amount of damage
//Recieved from health and armor
if(MyPlayer.DamageDone > 0)
{
if(MyPlayer.armor > 0)
{
//Half of Damage is Subtracted off Health
MyPlayer.health -= Damage/2;
//Full Damage is subracted from the Armor
MyPlayer.armor -= Damage;
//Tell us that the player has recieved damage
Debug.Log("Damage Recieved");
MyPlayer.DamageDone --;
//Set Regen Timer back to "0" so that the player cant
//Regenerate while being hit
MyPlayer.RegenTimerDuration = 0.0f;
}
}
``````

The function Mathf.CeilToInt accomplishes exactly that. You pass whatever you want rounded to it, and it returns the number rounded up to the nearest integer, like so:

``````    float damage = 0.5f;
int damageRoundedUp = Mathf.CeilToInt(damage);
``````

If you just want to remove decimals without any particular rounding type, you can just cast to an int:

``````MyPlayer.health -= (int)(Damage/2);

MyPlayer.armor -= (int)Damage;
``````

This will turn the value to an int and remove any decimals. If you want to round up, do like CHPederson said and use the math ceil function:

``````MyPlayer.health -= Mathf.CeilToInt(Damage/2);

MyPlayer.armor -= Mathf.CeilToInt(Damage);
``````