Showing posts with label Data Types. Show all posts
Showing posts with label Data Types. Show all posts

How to Declare a Double Variable

The Double class wraps a value of the primitive type double in an object. An object of type Double contains a single field whose type is double.

Holds signed IEEE 64-bit (8-byte) double-precision floating-point numbers that range in value from -1.79769313486231570E+308 through -4.94065645841246544E-324 for negative values and from 4.94065645841246544E-324 through 1.79769313486231570E+308 for positive values. Double-precision numbers store an approximation of a real number.
The Double data type provides the largest and smallest possible magnitudes for a number.
double data type is a double-precision 64-bit IEEE 754 floating point.
This data type is generally used as the default data type for decimal values, generally the default choice.
Double data type should never be used for precise values such as currency.
Default value is 0.0d.
Example: double d1 = 123.4

1. In the MainActivity.java file, add the below to the onCreate method. This will create a Double variable named myDouble.

double myDouble; 

2. Compile and run!

Resources:
http://developer.android.com/reference/java/lang/Double.html
http://www.tutorialspoint.com/java/java_basic_datatypes.htm
http://msdn.microsoft.com/en-us/library/x99xtshc.aspx


Create an Integer Variable

How to Create an Integer Variable

This will declare an integer variable

Integer was added in API Level 1

An integer is a number from -2147483648 to 2147483647. The integer data type is a 32-bit signed two's complement integer. Integer is generally used as the default data type for integral values unless there is a concern about memory. The default value is 0.

1. Create an Android project, if you don't already have one.

2.In the MainActivity.java file, add the code below to the onCreate method. This will create an integer variable named myInteger

    int myInteger;

3. Compile and run!

Next Recommended Article: Set an Integer Variable

Related Articles: