Specifying the type of a numeric literal

We have been using string and numeric constants like "hoho" or 1.23 in our programs. There is no doubt that the "hoho" is a string, but what is the data type of 1.23? It is numeric, but which numeric type? It turns out that by default, numeric literals with no decimal places are of type integer and those with decimals are of type double.

If you want to override those defaults, you can explicitly specify the data type of a numeric literal by appending a special character to its end. The following table shows the appending characters for some data types:

   Type     appending
            character

   Double   R or #
   Integer  I or %
   Long     L or &
   Short    S
   Single   F or !

Here are some examples:

   123     'is an integer
   123L    'is a long integer
   12.3    'is a double precision floating point number
   12.3F   'is a single precision floating point number

You can use these appending characters to control the data types of your numeric literals.

You can also see the data types of a literal, named constant or variable in a program by placing the cursor over it -- a popup box will give the data type.


Disclaimer: The views and opinions expressed on unofficial pages of California State University, Dominguez Hills faculty, staff or students are strictly those of the page authors. The content of these pages has not been reviewed or approved by California State University, Dominguez Hills.