Difference between revisions of "Variable data types"
m (ady624 moved page WebCoRE Variable Data Types to Variable data types without leaving a redirect) |
|||
Line 2: | Line 2: | ||
===Dynamic=== | ===Dynamic=== | ||
− | + | Dynamic variables are also known as loose-typed variables. They don't have a set type and can therefore contain any kind of data, from numbers, to strings, to booleans, etc. It is strongly recommended to use a strong-typed variable instead when the values you are planning on storing are of a certain type. | |
===String=== | ===String=== | ||
− | + | String variables can contain any text/number/boolean values represented as a string, for example: <code>"abc123"</code>. Note: storing numbers in string variables may lead to undesired results if you plan on comparing values. As strings, <code>"100"<code> is smaller than <code>"50"</code> because comparisons are made using character codes rather than overall values. Since 1 is before 5 in the alphabet, <code>"100"</code> is smaller than <code>"50"</code>. | |
===Boolean=== | ===Boolean=== | ||
− | + | Booleans are simple types that can contain one of two values: false or true. When converted to a string, these become <code>"false"</code> and <code>"true"</code>. When converted to a number, these become <code>0</code> and <code>1</code> | |
===Number (Integer)=== | ===Number (Integer)=== | ||
− | + | An integer variable can only store [https://en.wikipedia.org/wiki/Whole_number whole numbers], for example: <code>1</code> or <code>3983</code>. If you attempt to store a decimal value into an integer variable, the decimal digits are simply dropped (floor). | |
===Number (Decimal)=== | ===Number (Decimal)=== | ||
− | A variable | + | A decimal variable can contain [https://en.wikipedia.org/wiki/Rational_number rational numbers] in the decimal form, for example <code>6.3</code> or <code>100.18</code> or <code>209.292929</code>. It can also contain whole number values. |
===Date and Time=== | ===Date and Time=== | ||
Line 26: | Line 26: | ||
===Device=== | ===Device=== | ||
− | + | Device variables can store device handlers such as <code>Kitchen Light</code>. What's special about this type is that it can contain one or more devices (array). |
Revision as of 01:41, 26 March 2017
webCoRE supports several variable data types.
Contents
Dynamic
Dynamic variables are also known as loose-typed variables. They don't have a set type and can therefore contain any kind of data, from numbers, to strings, to booleans, etc. It is strongly recommended to use a strong-typed variable instead when the values you are planning on storing are of a certain type.
String
String variables can contain any text/number/boolean values represented as a string, for example: "abc123"
. Note: storing numbers in string variables may lead to undesired results if you plan on comparing values. As strings, "100"<code> is smaller than <code>"50"
because comparisons are made using character codes rather than overall values. Since 1 is before 5 in the alphabet, "100"
is smaller than "50"
.
Boolean
Booleans are simple types that can contain one of two values: false or true. When converted to a string, these become "false"
and "true"
. When converted to a number, these become 0
and 1
Number (Integer)
An integer variable can only store whole numbers, for example: 1
or 3983
. If you attempt to store a decimal value into an integer variable, the decimal digits are simply dropped (floor).
Number (Decimal)
A decimal variable can contain rational numbers in the decimal form, for example 6.3
or 100.18
or 209.292929
. It can also contain whole number values.
Date and Time
A variable of date and time represents a single point in time representing both date and time, for example 8/7/1980 08:39:29 AM
.
Date
A variable of date represents a single day, for example 8/7/1980
.
Date and Time
A variable of time represents a single point in time that can happen each day, for example 08:39:29 AM
.
Device
Device variables can store device handlers such as Kitchen Light
. What's special about this type is that it can contain one or more devices (array).