How to make text display normaly?

I have a GUI that spawns the value of stamina which is a Float value so it can go down slowly, but the only problem is when it displays it shows a eff load of digits too, here is my script, please tell me how to make so it only displays the closest number? so instead of 40.2357283% it shows 40%

(I don’t put it all because its VERY LONG) It basically controls the whole character so I cut it up to the important parts:

public var Stamina : float = 100;

function Running () {
Stamina = Stamina - 0.1;
}

function OnGUI () {
GUI.Box (Rect (360,Screen.height - 30,120,50), “Stamina: “+Stamina+”%”);
}

Use:

stamina.ToString("f0")

–Eric

Really appreciate it, where would I put that in my code?
At the end? just after the second " right?

Like this? GUI.Box (Rect (360,Screen.height - 30,120,50), “Stamina: “+Stamina+”%” stamina.ToString(“f0”))

EDIT:
Gave me error, sorry if it makes me seem dumb that I can’t figure out the answer you gave me D;

I did this: it deleted most errors but gave me Assets/Game/Player/Scripts/PlayerMovement.js(216,92): BCE0044: unexpected char: 0x0.

GUI.Box (Rect (360,Screen.height - 30,120,50), "Stamina: "+Stamina.ToString(“f0”));

Here is a reference to format specifiers for you:

And this reference shows some floating point examples:

= Ed =

These are all for C# and VB. I am using JS (JavaScript)

Bump, please help guys!

No they aren’t. .NET is .NET (or technically Mono in Unity) regardless of language. ToString(“f0”) works identically in all languages. You unexpected char error is probably because you copy and pasted a null character into your text; try manually deleting and replacing the return at the end of the line.

–Eric

I got it to work, Thanks. I feel stupid, I guess when I made this post my mind wasn’t awake. Marking as solved…