How to keep Unity from rounding floats?

I am using this code to round my time(float) to two decimals. I then show it using a GUI label.

		dynamicContent = player.thisleveltime;
	dynamicContent = Mathf.Round(dynamicContent * 100f) / 100f;

However, the problem with it is that when the float equals something point zero (ex: 9.0) unity rounds it to 9 with out the decimal point and then immediately adds it back in when it changes to 9.1. What ends up happening is that the decimal point and the digits behind it flash every second. Is there any way to stop this?

The problem isn’t rounding of the number itself - when you convert a float to a string, it uses the smallest number possible unless you tell it exactly what you want.

So when you convert the number to a string, use something like this…

[Your Float].ToString(“0.0”);

This would always show one digit and one decimal place - no more, no less.

For more details you could check out Custom numeric format strings | Microsoft Learn