printing a zero

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a program that performs calculations and displays a four digit number.
Sometimes the calculation results in a number like 0854, but my program
displays it as 854. How can I force the program to display the leading zero,
when the first digit is a zero? I'm only dealing with the integer data type.
 
Instead of using integers you could use a string and determine if the string
is shorter than 4 characters long. If it was shorter you could just add a
zero in front of the string.
 
Sometimes the calculation results in a number like 0854, but my program
displays it as 854. How can I force the program to display the leading zero,
when the first digit is a zero? I'm only dealing with the integer data type.

number.ToString("0000")
 
Candace said:
I have a program that performs calculations and displays a four digit number.
Sometimes the calculation results in a number like 0854, but my program
displays it as 854. How can I force the program to display the leading zero,
when the first digit is a zero? I'm only dealing with the integer data type.

..ToString("0000")
 
Back
Top