Float check not returning the right value.

Something very weird is going on, I’m trying to check if a float called fireDelay is lower than 0. Which, according to what I programmed, it is. But it seems that it doesn’t work.
I made a boolean check that writes in the Debug.Log, and the actual float value that writes in the debug log.

public float fireDelay = 0.0f;

public void PrimaryFire(RaycastHit hit)
        bool fireDelayLower = fireDelay <= 0.0f;
        Debug.Log("fireDelayLower = " + fireDelayLower);

        if (fireDelay <= 0.0f)
            Debug.Log(pickupOwner.GetComponent<AudioSource>(), pickupOwner);
            this.fireDelay = fireRate;
            pickupOwner.GetComponent<AudioSource>().PlayOneShot(gunSound[Random.Range(0, gunSound.Length - 1)]);

        if (currentClip <= 0)

fireDelayLower = False

And in the inspector itself…
alt text
I understand that it’s -0.02etc because of the floating point error. But shouldn’t it be -0.00000001 instead?

What exactly is going on here and how do I fix it?

The Unity editor automatically rounds any float that is output by the console; I suspect it applies the ToString method internally, which rounds to one decimal. Anyway, you can make the console output the verbose float like this:


Where F4 indicates the number of decimals you want to show.

See Standard Numeric Format Strings for further information.