Problem with division operation

Hello, everyone!
I’m have a problem here. This is my code:

HealthPrecent = (RealHealth / Health) * 100.0f;
UE_LOG(LogTemp, Warning, TEXT("%s - RealHealth is %d"), *GetName(), RealHealth);
UE_LOG(LogTemp, Warning, TEXT("%s - Health is %d"), *GetName(), Health);
UE_LOG(LogTemp, Warning, TEXT("%s - HealthPrecent is %f"), *GetName(), HealthPrecent);

This code run OnBeginPlay and next one when Unit have a damage. So, on start I have that in log:

LogTemp:Warning: Enemy - RealHealth is 500
LogTemp:Warning: Enemy - Health is 500
LogTemp:Warning: Enemy - HealthPrecent is 100.000000
LogTemp:Warning: MyUnit - RealHealth is 1500
LogTemp:Warning: MyUnit - Health is 1500
LogTemp:Warning: MyUnit - HealthPrecent is 100.000000

That correct. 500/500*100=100

But, when unit has a damage I see this in Log:

LogTemp:Warning: MyUnit has damage!
LogTemp:Warning: MyUnit - RealHealth is 1400
LogTemp:Warning: MyUnit - Health is 1500
LogTemp:Warning: MyUnit - HealthPrecent is 0.000000
LogTemp:Warning: Enemy has damage!
LogTemp:Warning: Enemy - RealHealth is 400
LogTemp:Warning: Enemy - Health is 500
LogTemp:Warning: Enemy - HealthPrecent is 0.000000

??? 400/500*100=80…

Why I’ll got null here?

Thanks!

Cause 400/500 = 0 in C++.
You need to convert your values to float :wink:

Another example to be clear. In C++:

  • 1 / 2 = 0
  • 1.0 / 2.0 = 0.5

Ou, that’s the problem) Great!
Many thanks for quick help!