How to display extra 0 at the end of decimal
Hi. I'm using this to display my rounded to 2 decimal points float:
myValue = Mathf.Round((someOtherValue + someOtherValue2) * 100) / 100;
guiObject.text = "Value: " + myValue;
The problem is, that when myValue is eg. 1.50, it displays 1.5 but i want it to display 1.50. When myValue is 1.55, it's ok. What can i do to display my extra zero at the end on myValue?
Comment
Best Answer
Answer by Statement · Nov 22, 2015 at 06:27 PM
Check out standard numeric format strings on MSDN, string.Format or Formatting Numeric Results Table.
Here's a snippet you can try:
guiObject.text = String.Format("Value: {0:F2}", myValue);
Answer by jmarcos007 · Aug 06, 2019 at 03:52 AM
float myValue; Text canvasText; myValue = Mathf.Round(myValue * 100) / 100; canvasText.text = myValue.ToString("F2") + " some text here";