- Home /
How to show a percent sign in a label.
Hi, I have a label that's supposed to show a number and put a percentage sign after it. However, only the number is showing, the percentage sign doesn't show up.
The string looks like this: (Mathf.RoundToInt(playerScript.fuel / playerScript.beginningFuel * 100f)).ToString() + "%"
I know that % is used as an operator in C#, so it's not "supposed" to be shown. How could I get around this?
Answer by Eric5h5 · Jul 05, 2014 at 06:46 PM
Anything in a string is just a string, it's not an operator and certainly is supposed to be shown. The only exception is the "\" character, which is an escape character. I expect the label just isn't wide enough. By the way, you don't need to use ToString() when you're concatenating numbers with strings since everything is converting to a string anyway.
But even if I simply put "%" as the text of the label, it doesn't show up. So it's not related to the width. For example, 123%456 shows up as 123456.
Edit: oh, it was because the font doesn't have a percent sign...
Your answer
Follow this Question
Related Questions
How do I get a list to randomly select.... 1 Answer
Find what word is selected by mouse in GUI.Label 0 Answers
Changing color of select section of text 0 Answers
Getting the text from UIInput 1 Answer
Optimizing OnGUI 1 Answer