i.ToString().PadLeft(4, '0')
– okay, but doesn’t work for negative numbers
i.ToString("0000");
– explicit form
i.ToString("D4");
– short form format specifier
$"{i:0000}";
– string interpolation (C# 6.0+)
More Related Contents:
- Format Number like Stack Overflow (rounded to thousands with K suffix)
- Format a number with commas and decimals in C# (asp.net MVC3)
- Format a number with commas and decimals in C#
- How to escape braces (curly brackets) in a format string in .NET
- Double to string conversion without scientific notation
- How can I String.Format a TimeSpan object with a custom format in .NET?
- Using String Format to show decimal up to 2 places or simple integer
- Format XML string to print friendly XML string
- Formatting doubles for output in C#
- format date in c#
- Format TimeSpan greater than 24 hour
- What does {0} mean when found in a string in C#?
- Parse a Number from Exponential Notation
- Custom numeric format string to always display the sign
- JSON formatter in C#?
- Best way to display decimal without trailing zeroes
- Problem parsing currency text to decimal type
- Format A TimeSpan With Years
- How can I format a nullable DateTime with ToString()?
- How to generically format a boolean to a Yes/No string?
- Use a custom thousand separator in C#
- Two Decimal places using c#
- How to split string preserving whole words?
- How do I format a Decimal to a programatically controlled number of decimals in c#?
- Changing font for richtextbox without losing formatting
- File-size format provider
- Pad left or right with string.format (not padleft or padright) with arbitrary string
- How do you set the cout locale to insert commas as thousands separators?
- Formatting Large Numbers with .NET
- EPPlus – LoadFromCollection – Text converted to number