I’m using Time.deltaTime to regenerate my player’s HP when at a “Heath Station”. The code works fine; however, I’ve encountered an unwanted issue.

When using this method, the UI updates with unwanted decimals. It should appear as an integer at all times:

No decimals.
I’m not exactly sure how to check if there are decimals. What I have tried is to multiply by 1 in hopes of making it a whole number rather than a decimal(float).
PlayerHealth.playerHp += Time.deltaTime * 10f *1;
// Multiplying by "1" trying to remove the decimals
I know I’ve done this before but cannot remember how.
1 Like
hpTxt.text = "Health: " +Mathf.CeilToInt(playerHp) + " / " + maxPlayerHp;
Ok, I remembered how I did it last time. Basically on my PlayerHealth script, I needed to add Mathf.CeilToInt() and that removed that decimals. Brain fart!!! 
1 Like
Another tip is to avoid floats altogether and stick to ints.
It makes a lot of things easier if health is an int 0…100. If you need finer control, make it 0…1000 and divide by ten before displaying in the UI and so on.
1 Like
Just curious, is there any significant memory usage difference between a float and int? Does one process faster than the other?
I do appreciate the advice!
Significant, for most games and for something like a health system, no. In a large-scale (millions of operations) system, floating point math would be slower in theory. Memory is the same, assuming you are using the regular int and float classes which are 32bit.
Ints however are much easier to compare. Checking for int equal or lower to zero will be correct everytime and can be easily debugged. Triggering an effect at 77% health will be precise with an int. Floats need to be compared against an error margin which can potentially fail (Mathf.Approximately or checking if smaller than 0.01 when we actually mean zero) and these methods are generally slower.