-3

I have this code:

phrasesPage.Title = "Timer: " + AS.timerSeconds.ToString();

The number of seconds can be anything from 120 to 0. Is there a way that I can have that display as "Timer: " plus the numbers 120 ... 099 .. 002 ... 001 ... 000 . In other words I need the number to show as three digits with left padding of 0's

Alan2
  • 23,493
  • 79
  • 256
  • 450

2 Answers2

5

.ToString("000") ought to work.

phrasesPage.Title = "Timer: " + AS.timerSeconds.ToString("000");

See Custom Numeric Formats for other examples of things you can do with the format string.

StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315
1
phrasesPage.Title = string.Format("Timer: {0:D3}", AS.timerSeconds);
hunter
  • 62,308
  • 19
  • 113
  • 113