有没有办法让我在C#中留下一个数字?

问题描述:

我有这样的代码:有没有办法让我在C#中留下一个数字?

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

的秒数可以是任何东西,从120到0。有没有一种方法,我可以有一个显示为“定时器”加号120 ... 099。 。002 ... 001 ... 000。换句话说,我需要的数字显示为三个数字与左填充0的

+0

这是你正在寻找https://*.com/questions/4325267/c-sharp-convert-int-to-string-with-padding-zeros –

+1

相同的答案之前,请做一个搜索张贴问题。 – itsme86

.ToString("000")应该工作。

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

请参阅Custom Numeric Formats其他关于格式化字符串的例子。

phrasesPage.Title = string.Format("Timer: {0:D3}", AS.timerSeconds);