Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

[solved]float: debug.log says 45, but BitConverter.GetBytes says another value

Discussion in 'Getting Started' started by sefiroths, Jun 22, 2018.

  1. sefiroths

    sefiroths

    Joined:
    Dec 13, 2014
    Posts:
    23
    Hi, I have a strange issue... why startingAngle writes in debug 45 but in bytes is another number 4.5000003814697265625E1 (http://www.binaryconvert.com/result_float.html?hexadecimal=42340001)

    Code (CSharp):
    1. float startingAngle = pinguinoMio.transform.eulerAngles.y;//is 45 in inspector
    2. float[] angles={0,45,90,135,180,-135,-90,-45};
    3. System.Byte[] bytes0 = System.BitConverter.GetBytes(startingAngle);
    4. System.Byte[] bytes1 = System.BitConverter.GetBytes(angles [1]);
    5. Debug.Log(System.BitConverter.ToString (bytes0));//01-00-34-42
    6. Debug.Log(System.BitConverter.ToString (bytes1));//00-00-34-42
    7. Debug.Log (angles [1].ToString("F64") +" "+ startingAngle.ToString("F64"));//45.0000..... 45.00000...
    I have seen that
    Code (csharp):
    1. Debug.Log (angles [1].ToString("g9") +" "+ startingAngle.ToString("g9"));//45.0000..... 45.00000...
    gave me different reault
     
    Last edited: Jun 22, 2018