Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    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.