0

I wrote this script for a timer object in a unity game I'm working on.

    void DisplayTime(float timeToDisplay)
    {
        timeToDisplay += 1;
        TimerText.text = string.Format("{0}", timeRemaining);
    }

Right now the Timer displays 00.000. How can I make it so It only displays the first two digits?

Thanks for your time :) <3

maksy
  • 13
  • 4
  • 1
    [Numeric format specifier (N)](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#numeric-format-specifier-n) _"The precision specifier indicates the desired number of digits after the decimal point."_ so, in your case `"{0:N0}"` – Fildor Jun 08 '21 at 07:09
  • Or custom if you always want 2 digits: `"{0:00}"` See https://dotnetfiddle.net/xVlaDW If you want to have the group separator for bigger numbers: `"{0:#,#00}"` – Fildor Jun 08 '21 at 07:13
  • 1
    Thank you so much @Fildor :)) I was having a really hard time understanding the documentation. – maksy Jun 08 '21 at 07:13

0 Answers0