Sponsored Ad

Sunday, March 13, 2011

How to Add Leading Zeros to a Number using C#

This program will help you to add leading zero to a given number you can specify D5 if you want that total number of digits should be 5 including zeros.

How to Add Leading Zeros to a Number using C#

C# Sample Code to Add Leading Zeros:

using System;
using System.Globalization;
namespace MyApp
{
    class Leading_zero_class
    {
        static void Main()
        {
            int myAmount = 475;

            Console.WriteLine(myAmount.ToString("D6", CultureInfo.InvariantCulture));
            Console.WriteLine(myAmount.ToString("D5", CultureInfo.InvariantCulture));

            Console.Read();
        }
    }
}

No comments:

Post a Comment

Sponsored Ad

Development Updates