if(12f > 12f) = true?

Hi! I am making a Character controller. I am almost finished, I just needed to fix a bug using the following if statement:

if(GetColliderLimit(Vector2.up) > yLimitTop) {
                Debug.Log(GetColliderLimit(Vector2.up) + " > " + yLimitTop + " = " + (GetColliderLimit(Vector2.up) > yLimitTop));
                //DO THINGS TO FIX THE BUG HERE

However, there is a case when it enters the conditional when it shouldn’t. That is when both numbers are 12.


As far as I know, 12 > 12 is not True. Please help! What am I doing wrong? If this is a floating point error, how can I print the full float number (not rounded)?

I made A LOT of Math like this in my script, and this is the only time I got an error like this.

Thank you in advance.

It is almost certainly a floating point error. 12.000001 will appear as 12, but still register as greater than 12.

To fix this, you could rearrange your if condition to use Mathf.Approximately. Something like this:

if(GetColliderLimit(Vector2.up) > yLimitTop && !Mathf.Approximately(GetColliderLimit(Vector2.up), yLimitTop)){

@DavidRochin Edited to working code.

hmmm. i know “Print” works for accurate councel output with floats. Floats print with the decimals. Vector2 and 3 do NOT. hope this helps

		Vector2 v22 = new Vector2 (5.45433f, 6.985495f);
             print (v22.x+"/"+v22.y);