Type Description
| char | Single byte data type, can store a single character or number 0 to 255 |
| short | 16-bit integer, can store numbers from �32,768 to 32,767 |
| int | 32-bit integer, can store from �2,147,483,648 to 2,147,483,647 |
| String | Stores a string of characters |
| float | A 32-bit floating point number. Accuracy normally about 6 decimal places,
but varies depending on the size of the number being stored. |
| bool | a variable that stores either 'true' or 'false' |
You will normally only need to use the int and String data types. The smaller types
are only useful for conserving memory if you are creating a very large number of variables.
To declare a variable, write the type followed by the variable name, then a semicolon.
For example:
int my_variable;
declares a new 32-bit integer called my_variable
WARNING: When using the float data type, you may find that the == and != operators
don't seem to work properly. For example:
float result = 2.0 * 3.0;
if (result == 6.0) {
Display("Result is 6!");
}
may not always work. This is due to the nature of floating point variables, and the solution
is to code like this:
float result = 2.0 * 3.0;
if ((result > 5.99) && (result < 6.01)) {
Display("Result is 6!");
}
The way floating point numbers are stored means that 6 might actually be stored as 6.000001
or 5.999999; this is a common gotcha to all programming languages so just be aware of it
if you use any floating point arithmetic.
|