·  C++ – Syntax – Variables – double

 

- Info:

  - This tutorial shows how to create double and convert it to other Primitive Types.

 

- Procedure:

  - Create C++ Console Application Test.cpp.

 

    Test.cpp

    #include <iostream>

    using namespace std;

   

    int main () {

   

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

      double value    = 'A';

             value    =  65;    // Decimal     ASCII value.

             value    = 0101;   // Octal       ASCII value.

             value    = 0x41;   // Hexadecimal ASCII value.

             value    = 34.55// 34.549999

   

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

      char   to_char  = value;  // 34

      short  to_short = value;  // 34

      int    to_int   = value;  // 34

      long   to_long  = value;  // 34

      float  to_float = value;  // 34.549999

      cout << to_char << " " << to_long << " " << to_float << endl; //" 34 34.55

   

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

      cout << value << "" << scientific << "" << value;             //34.553.455000e+01

   

      return 0;

    }