Debug.Log(2000.0f * 000.1f); is 200

Now that you have had your coffee, don’t forget about floating point imprecision:

// @kurtdekker: don't forget about floating point imprecision
using UnityEngine;
public class FloatingPointImprecision : MonoBehaviour
{
    void Start ()
    {
        float a = 2000.0f;
        float b = 0.1f;
        float product = (a * b);
        float answer = 200;

        Debug.Log( "a = " + a);
        Debug.Log( "b = " + b);
        Debug.Log( "product of a*b = " + product);
        Debug.Log( "answer = " + answer);
        Debug.Log( "does product equal answer? " + (product == answer));
        Debug.Log( "does a*b equal answer? " + ((a * b) == answer));
    }
}

7399994--904268--floating_point_imprecision.png

Your mileage almost certainly will vary. Choose an epsilon term and know it well.

1 Like