C# Display custom formatting for zero and negative float numbers using String.Format() method

Program

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Demo for custom formatting for zero and negative number");

            Console.WriteLine(String.Format("{0:0.00;minus 0.00;zero}", 512.4567));  
            Console.WriteLine(String.Format("{0:0.00;minus 0.00;zero}", -512.4567)); 
            Console.WriteLine(String.Format("{0:0.00;minus 0.00;zero}", 0.0));       

            Console.WriteLine();  
        }
    }
}

Output

Demo for custom formatting for zero and negative number
512.46
minus 512.46
zero

Leave a Comment

error: Alert: Content is protected!!