Real number literal

We can use decimal as real number literal. For example,


using System;

class Program
{
    static void Main(string[] args)
    {
        double d = 1.123;

        Console.WriteLine(d);
     }
}

The output:


1.123

Exponential literal


using System;

class Program
{
    static void Main(string[] args)
    {
        double million = 1E06;

        Console.WriteLine(million);
     }
}

The output:


1000000

'Integer type literal vs real number literal'

If a literal has a decimal point or has an exponential symbol, it is a double.


using System;

class Program
{
    static void Main(string[] args)
    {

        Console.WriteLine(1.GetType());

        Console.WriteLine(1.6.GetType());

        Console.WriteLine(1E06.GetType());
     }
}

The output:


System.Int32
System.Double
System.Double
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.