·  C# – Syntax – Variables – float

 

- Info:

  - This tutorial shows how to create, convert and display float.

  - float is implicitly converted to double.

  - This tutorial is based on http://msdn.microsoft.com/en-us/library/b1e65aza(VS.80).aspx.

 

- Procedure:

  - Create C# Console Application Test.cs.

 

    Test.cs 

    using System;

   

    class Test {

   

      static void Main(string[] args) {

   

        //CREATE.------------------------------------------------------------------------

        float   value    =         10.5f;            //Define constant as float.

                value    =         10.5F;            //Define constant as float.

                value    = (float) 10.5;             //Decimal.     Expicit conversion from double.

                value    =         10;               //Decimal.     Implicit conversion from int.

                value    =         0xA;              //Hexadecimal. Implicit conversion from int.

   

        //CONVERT.-----------------------------------------------------------------------

        char    _char    = (char   ) value;

   

        sbyte   _sbyte   = (sbyte  ) value;

        short   _short   = (short  ) value;

        int     _int     = (int    ) value;

        long    _long    = (long   ) value;

   

        byte    _byte    = (byte   ) value;   

        ushort  _ushort  = (ushort ) value;   

        uint    _uint    = (uint   ) value;   

        ulong   _ulong   = (ulong  ) value;

   

        double  _double  =           value;

        decimal _decimal = (decimal) value;

        

        //DISPLAY.-----------------------------------------------------------------------

        Console.WriteLine(value);    

 

      }

   

    }