public Transform player; 
public Text scoreText;

// Update is called once per frame
void Update()
{
  int abs = 29;
  int z = player.position.z;
  scoreText.text = (abs + z).ToString("0"); 

}
Answer from sunghee on Stack Overflow
🌐
Unity
discussions.unity.com › scripting
Convert float to string - Scripting - Unity Discussions
January 20, 2007 - Hey all, I’m sure this is common and simple, but I couldn’t find it in the docs… How do I convert a float to a string. i.e. the following does not work: // var weightfield = GameObject.Find(“WeightField”).GetComponent(“TextMesh”); weightfield.text = totalWeight; // However, if ...
Discussions

c# - Unity: How to convert a float value to a 00:00 string? - Stack Overflow
I have a timer that runs in the background and at the end of the level i want to show the leaderboard. i want to take this timer and convert it to 00:00 format 00 (Minutes) : 00 (Seconds) (i.e 01:4... More on stackoverflow.com
🌐 stackoverflow.com
Convert float to string - Scripting - Unity Discussions
Hey all, I’m sure this is common and simple, but I couldn’t find it in the docs… How do I convert a float to a string. i.e. the following does not work: // var weightfield = GameObject.Find(“WeightField”).GetComponent(“TextMesh”); weightfield.text = totalWeight; // However, if ... More on forum.unity.com
🌐 forum.unity.com
2
January 20, 2007
Convert Float to a String - Scripting - Unity Discussions
Hey guys, I have found loads of resources coverting from a string to a float or int (parsing, etc), but I can’t seem to make it work the other way. I have no doubt missed something fairly obvious, but I can’t seem to work this one out. It is for a GUI horizontal slider, I want the results ... More on discussions.unity.com
🌐 discussions.unity.com
1
August 12, 2009
Float to String C# - C# & .NET - Unity Discussions
This is a relatively simple question. I created a UI that is supposed to show the health of the player. However, because the health of the player is a float value, I cannot use it to update the text of the UI, which is a string. Any suggestions on how to make this work? Thanks. More on discussions.unity.com
🌐 discussions.unity.com
1
December 23, 2015
🌐
Unity
discussions.unity.com › scripting
Convert Float to a String - Scripting - Unity Discussions
August 12, 2009 - Hey guys, I have found loads of resources coverting from a string to a float or int (parsing, etc), but I can’t seem to make it work the other way. I have no doubt missed something fairly obvious, but I can’t seem to work this one out. It is for a GUI horizontal slider, I want the results ...
🌐
Unity
discussions.unity.com › scripting › c# & .net
Float to String C# - C# & .NET - Unity Discussions
December 23, 2015 - This is a relatively simple question. I created a UI that is supposed to show the health of the player. However, because the health of the player is a float value, I cannot use it to update the text of the UI, which is a…
Find elsewhere
🌐
Unity
discussions.unity.com › unity engine
How to convert float to string? - Unity Engine - Unity Discussions
July 26, 2020 - Unity gave me the error message “error CS0029: cannot implicitly convert type ‘float’ to ‘string’” My code is using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class DisplayScore : MonoBehaviour { public Text test; public bool flag = true; // Use this for initialization void Update() { test.text = GameObject.Find("Button Score").GetComponent ().playerScore; } } so how would I convert th...
🌐
Unity
discussions.unity.com › scripting
float.ToString() Format - Scripting - Unity Discussions
October 22, 2020 - Hi, float my_float = 1.1234f; Debug.Log(my_float.ToString("F2")); I just realize that this command show the float in the device localisation format. Example : -Log in UK : “1.12” -Log in France : “1,12” The decimal…
🌐
YouTube
youtube.com › watch
Float to String with GUI Countdown - Unity3D and Playmaker - YouTube
Join our Filmstorm Motion Library: https://www.patreon.com/filmstormIn this video I answer another fan question about converting a float to a string value an...
Published: October 18, 2015
🌐
Reddit
reddit.com › r/unity2d › how can i display up to x decimal places of a float?
r/Unity2D on Reddit: How can I display UP TO x decimal places of a float?
August 7, 2023 -

It seems like this should be really obvious but I'm having a hard time finding an answer. I'm trying to display a float as a string. Here's the behavior I want (in this example I'm displaying up to 2 decimal places):

float: 1 > string: "1"
float: 1.23456 > string: "1.23"

The issue I'm having is most of the methods I'm finding for rounding/truncating the float (I don't really care if it's rounded or truncated) force zeros into the string if there is no decimal. So in the above example it would format float: 1 > string: "1.00" which is not what I want.

Thanks in advance!

🌐
Unity
discussions.unity.com › scripting
How Do I Convert String To Float? - Scripting - Unity Discussions
August 16, 2022 - I had to answer this, because I could find no answer anywhere. I tried Parse and TryParse. I wrote my string to the Debug Log and saw that the string contained only a number. So, I tried the Try Catch and found the following error: · Here is my solution: OKtoFire = true; string angle1 = ...
🌐
Unity
discussions.unity.com › getting started
How to convert float to int for display as string? - Getting Started - Unity Discussions
July 10, 2018 - [FIXED] Hello sir, I’m a newbie and sorry if this is a stupid question. I try to display character health by using “ToString” from the character health source but the problem is it comes with a lot of float number like 50.0545454352435 so yeah, very messy.
🌐
Unity
discussions.unity.com › archived forums › questions & answers
how to convert a float to string[] - Questions & Answers - Unity Discussions
July 11, 2015 - hello sorry i am new to unity and i want to know how to convert from float to string the thing is when i use “ToString” command it gives me that you cannot convert string to string here is my line of code: InXMLGui.e…
🌐
Unity
discussions.unity.com › questions & answers
Convert Float to String? or 3D Text = Float? - Questions & Answers - Unity Discussions
March 2, 2010 - (note: it may be an Integer not ... i have this set up on my monster: var hitPoints = 100.0; var Player: Transform; var Self: Transform; var TextofMonster: Transform; function OnMouseOver ......
🌐
Reddit
reddit.com › r/unity2d › how do i convert a string to a float
r/Unity2D on Reddit: How do i convert a string to a float
July 17, 2023 -

im currently using this code

using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using JetBrains.Annotations;
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Windows;

public class output : MonoBehaviour
{
    public Text main_output;
    public float value = float.Parse(TEST.playerName, CultureInfo.InvariantCulture.NumberFormat);

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        main_output.text = value.ToString();
    }

}