Number 0 not showing up in GUI.Button

Hello, Im trying to make a timer for my game and I need the number 0 to show in front of some numbers. For example :

02:01:01.

I did all the scripting and the timer works fine apart from the number 0 not showing up in front of the other numbers. For example, number 2 appears like 2 only ,not 02.

Is there any way to make it so it appears as 02 ? I tried to switch between float and int but it’s still the same.

Thank you.

// C# / UnityScript
var yourTimeString = “” + h.ToString(“00”) + “:” + m.ToString(“00”) + “:” + s.ToString(“00”)

You can to use string formatting of some sort: ToString() with a format specified, or String.Format(). Example:

#pragma strict

private var i : int = 4;

function Start() {
	Debug.Log(i.ToString("D2"));
	
	Debug.Log(String.Format("{0,2:D2}:{1,2:D2}:{2,2:D2}", 2, 4, 8));
}

http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx

http://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx