3 -> 0003 Simple String.Format Question!

  • Thread starter Thread starter Cat
  • Start date Start date
C

Cat

Hello.
I have an integer whose value varies from 0 to 9999.
I want to print it in a four-digit format.
Like,
0000
0001
0002
.....
9998
9999
I tried String.Format("{0:####}",val), but it didn't work. How can I do
this? Thanks.
 
Cat said:
I have an integer whose value varies from 0 to 9999.
I want to print it in a four-digit format.
Like,
0000
0001
0002
....
9998
9999
I tried String.Format("{0:####}",val), but it didn't work. How can I do
this? Thanks.

Try {0:0000} as the format string instead. Alternatively (and slightly
more compactly), you can call ToString directly on val:
val.ToString("0000")
 
Cat said:
Hello.
I have an integer whose value varies from 0 to 9999.
I want to print it in a four-digit format.
Like,
0000
0001
0002
....
9998
9999
I tried String.Format("{0:####}",val), but it didn't work. How can I do
this? Thanks.

String.Format("{0:d4}",val);

Bill
 
Back
Top