Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    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


    May 11, 2016
    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.