Float values not coming out correctly using operands in equation

So I have a couple float values, and I’m doing a simple subtraction. In this case the problem is -121.4729 - -121.4729 and the answer it prints is -2.288818E-05.

 float a = 35.5555f, b = -121.4729f;

float debugf = b  -  (-121.4729f);
Debug.Log(debugf);

Why doesn’t this equal 0?

edit: hmmm now that code is returning 0 but I have other values that are still incorrect. Not sure whats going on here

Floating point (im)-precision, I believe. You got a number super close to 0 but not quite. Not all numbers can be represented properly in floating-point format.

1 Like