In C# I have an integer value which need to be convereted to string but it needs to add zeros before:
For Example:
int i = 1;
When I convert it to string it needs to become 0001
I need to know the syntax in C#.
In C# I have an integer value which need to be convereted to string but it needs to add zeros before:
For Example:
int i = 1;
When I convert it to string it needs to become 0001
I need to know the syntax in C#.
See MSDN on format specifiers.
Here I want to pad my number with 4 digit. For instance, if it is 1 then it should show as 0001, if it 11 it should show as 0011.
Below is the code that accomplishes this:
I implemented this code to generate money receipt number for a PDF file.
Simply
To pad
int i
to match the string length ofint x
, when both can be negative:You can use: