Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Suggest] Vector2, Vector3... to implement System.IFormattable to use C# string interpolation format

Discussion in 'Getting Started' started by tam007, May 13, 2020.

  1. tam007

    tam007

    Joined:
    May 11, 2016
    Posts:
    3
    Here is my code:

    Code (CSharp):
    1. var v = new Vector2(1.234f, 5.678f);
    2. print("v= " + v.ToString("0.000"));
    3. print($"C# interpolation: v= {v:0.000}");
    4. print($"work-around: v= {v.ToString("0.000")}");
    You can see only the code lines with ToString("0.000") will print the exact result. I want to use $"C# interpolation: v= {v:0.000}" to print the exact result too. I feel it will be very clearly and less code when using C# interpolation only !
    I suggest Unity should rewrite the Vector2, Vector3.... to implement System.IFormattable. upload_2020-5-13_22-38-45.png upload_2020-5-13_22-36-59.png
     
    MikaelBergquist likes this.