Float and int question

Hi,

I have a noob question.
Say that I have two integers:

int a = 80;
int b = 0;

Below log suggests an outcome of “0” instead of float “0.8”

Debug.Log("Chance: " + (a - b) / 100);

I tried manually putting (float) in front of the equation, and it doesn’t work either.
I tried create a float variable to store the equation, but it’s still a fat “0”.

Can anyone point out what’s the underlying problem here? I want that “0.8”

Thanks!

it’s because your variables are ints, the 100 is an int (if you don’t use a type suffix and it doesn’t have a ., it’ll be an int). Sure you may convert your result to float, but the arithmetic is all ints.

Either a, b, or 100 needs to be typed as a float.

Try:
(a - b) / 100f

2 Likes

Ahh Thank you!