# How can I properly display the distance with the unit in a string on the UI?

I wrote a script for distance of car and I dont know how to make distance like this Distance: 156Km. I wrote this code:

distanceText.text = ((int)distance).ToString() + "Km";


It works only from 1 to 9; when it goes to 10 Km, it disappears but if I write it like this:

distanceText.text = ((int)distance).ToString() + " Km";


It show like this: from 1 to 9 -> "5 Km" and from 10 to 99 -> "99Km" but when it goes to 100 Km and above, it disappears. What code should I write for this to show always Km after the distance.

And I have one more question. I have a gameover canvas and I'd like in gameover canvas to show the final distance I make with PlayerPrefs but it doesn't work.

Here it shows how it does not work:

• Please keep your question to one question. For the first question, could you provide screenshots? I would also recommend using String.Format("%d Km", distance); – Cedric Martens Jun 30 '17 at 17:09
• if you like i can upload all code. – Driton Jun 30 '17 at 18:06
• I think I understand your problem, do you have one label saying "Distance : " and another seperate label saying "X Km"? – Cedric Martens Jun 30 '17 at 18:33
• Yes but if i make like this doesent work distanceText.text = ((int)distance).ToString() + "Km"; – Driton Jun 30 '17 at 18:41

Instead of having two labels. One for Distance : and one for X Km, you should only have one. Set the label like this :
distanceText.Text = String.Format("Distance : {0} Km",(int)distance);
The String.Format method allows you to easily format strings, the %d indicates you want it to be formated with an int. {0}` is where the argument 0 (distance) will be replaced.