Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C# – Multiplying Vector3 by float value returns rounded value

Unity2020
This string:

Debug.Log(new Vector3(1, 0, 0) * 1.25f);

returns (1.3, 0.0, 0.0).
Why?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It is just how the ToString override works. You can specify how the numbers are format by using different overrides. For example:

var vector = new Vector3(1, 0, 0) * 1.25f;
Debug.Log(vector.ToString("F3"));

Or individually log out the values:

var formatString = "F3";
Debug.Log($"Vector is X:{vector.X.ToString(formatString)}, Y:{vector.Y.ToString(formatString)}, Z:{vector.Z.ToString(formatString)}");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading