Format 0 specially for double value format in CSharp

Description

The following code shows how to format 0 specially for double value format.

Example


using System;//from  w  w w  .  j  a va 2s.  c o  m

public class MainClass
{
    public static void Main()
    {


        double posValue = 1234;
        double negValue = -1234;
        double zeroValue = 0;

        string fmt2 = "##;(##)";
        string fmt3 = "##;(##);**AAA**";

        Console.WriteLine(posValue.ToString(fmt2));
        Console.WriteLine(negValue.ToString(fmt2));

        Console.WriteLine(zeroValue.ToString(fmt3));
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var