# Convert Float to String? or 3D Text = Float?

**URL:** https://discussions.unity.com/t/convert-float-to-string-or-3d-text-float/1817
**Category:** Questions & Answers
**Created:** [March 2, 2010, 3:23am UTC](https://discussions.unity.com/t/convert-float-to-string-or-3d-text-float/1817 "2010-03-02T03:23:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![system](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/system/32/97283_2.png) [@system](https://discussions.unity.com/u/system)
#### Post date: [March 2, 2010, 3:23am UTC](https://discussions.unity.com/t/convert-float-to-string-or-3d-text-float/1817/1 "2010-03-02T03:23:13Z")

</div>

(note: it may be an Integer not a float, im not quite sure) so in my "RPG game" i'm setting up a very simple click to auto attack system, so far i have this set up on my monster:

```
var hitPoints = 100.0;

var Player: Transform;

var Self: Transform;

var TextofMonster: Transform;

function OnMouseOver () {

if (Input.GetMouseButtonDown(1)) {

Player.GetComponent(AttackSomething).AttackMonster(Self);

   }

}

function ApplyDamage(DamageofWeapon) {

print(DamageofWeapon);

    hitPoints -= DamageofWeapon;

TextofMonster.GetComponent(TextMesh).text = "DamageofWeapon";

    if (hitPoints 
    {

        DestroySelf();

    }

}

function DestroySelf()

{

print("destroy")

}
```

now the DamageofWeapon is an Float sent from another script, its a random number (depending on what weapon you use). I have the TextofMonster set up as a 3d Text that is a child of the monster, and it's original text is set to a space (nothing). I want it so everytime the function is called, it shows the damage that is caused (the DamageofWeapon) but i tried just putting that in there but i get an error code. I figure this is because DamageofWeapon is an Float and not a String, so alas my question, can i turn the number from DamageofWeapon into a string, or make the 3D text display that Float?

---

<div class="post-metadata">

### Author: ![Eric5h5](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/eric5h5/32/44225_2.png) [@Eric5h5](https://discussions.unity.com/u/Eric5h5)
#### Post date: [March 2, 2010, 4:02am UTC](https://discussions.unity.com/t/convert-float-to-string-or-3d-text-float/1817/2 "2010-03-02T04:02:11Z")

</div>

Use .ToString():

```auto
var someNumber = 10.5;
GetComponent(TextMesh).text = someNumber.ToString();

```

---

<div class="post-metadata">

### Author: ![Ashkan\_gc](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@Ashkan\_gc](https://discussions.unity.com/u/Ashkan_gc)
#### Post date: [March 2, 2010, 7:21am UTC](https://discussions.unity.com/t/convert-float-to-string-or-3d-text-float/1817/3 "2010-03-02T07:21:14Z")

</div>

all classes in .NET/MONO has a method called ToString that returns a string representing the value of that class. you can override that class for your own classes too. let's say you have a point class then you can write

```auto
class point
{
public float x;
public float y;
override string ToString ()
{
return x.ToString () + " , " + y.ToString ();
}

```

you can use this function to create great strings that help in debugging your game. if you don't create a function yourself it will return the class name. to convert back string to float,double, int you can use int.Parse (yourstring) or float.Parse (yourstring)
