- Home /
How to reduce number of digits in coordinate points?
I use this code to display the 3D coordinates in the game screen, however they are displayed to four digits ie. 27.5693. My question is, can I lessen this to say.. 27.5 ?
GUI.Label(Rect(10, 10, 500, 100), " X = " + transform.position.x + " Y = " + transform.position.y + " Z = " + transform.position.z);
Answer by Bunny83 · Aug 09, 2017 at 12:39 AM
You can use:
transform.position.x.ToString("0.0")
for one decimal digit. btw you can simply use ToString on the whole position to print all 3 components at once. The format string will be applied on each component:
transform.position.ToString("0.0")
Answer by bobisgod234 · Aug 09, 2017 at 12:41 AM
The xyz values from the Vector3 are just regular C# floats and as such standard C# formatting is available
Example:
GUI.Label(Rect(10, 10, 500, 100), " X = " + transform.position.x.ToString("F1") + " Y = " + transform.position.y.ToString("F1") + " Z = " + transform.position.z.ToString("F1"));
Will display the X, Y and Z values to 1 decimal place.
Your answer
Follow this Question
Related Questions
Changing Health Display GUI 1 Answer
Text Mesh Pro - Unicodes 0 Answers
GUI Display in game cash help 1 Answer
Picking one of two numbers. 1 Answer
4.6 GUI Text help 1 Answer