[SOLVED]Can't figure this out

Why does the following result in an output of zero:

Debug.Log(1/5);

And, actually, this will result in a value of 1:

Debug.Log(5/4);

It appears it is rounding floats to ints, but I didn’t explicitly tell it to do any such thing. And it isn’t just in Debug.Log. Any float or double variable, whose value should be set to a fraction, is rounding to an int.

Further investigation shows that it is something to do with the ‘/’ operator. Multiplying by decimal values such as .2, .3 seems to work fine.

It’s correct behavior. You’re only specifying ints, so gives you an int for the answer, which is normally what you want. Use floats, and you get a float.

–Eric

To illustrate this, try using Debug.Log(1/5.0);

Ahh. Thanks.