Conversion Between Data Types

Conversion Between Data Types

Welcome to our Knowledge Base

Documentation | Blog | Demos | Support

< All Topics
Print

Conversion Between Data Types

Zim performs conversions and operations between data types in a different manner than other application development languages. The rules for conversions are embedded in Zim itself, and when performing conversions or comparisons, these rules govern how the different data types are handled.

Implicit Conversions

In general, when you write an expression, you can use objects or literals of any data type, in any combination. However, when the software encounters an expression containing values with mixed data types or a data type incompatible with the requirements of the expression, it applies a number of rules for converting the data types should conversion be necessary.

Character-to-character Comparisons

  1. When values are being compared, VARALPHA and VARCHAR values are treated as if they were ALPHA and CHAR values, respectively.
  2. When two values of type ALPHA are being compared, an ALPHA-type (case insensitive) comparison is performed.
  3. When two values of type CHAR are being compared, a CHAR-type (case sensitive) comparison is performed.
  4. When two values are being compared, one of type CHAR and one of type ALPHA, an ALPHA-type (case insensitive) comparison is performed.

Character-to-number Conversions

  1. When two values – only one of which is a number type – are compared or are processed in an arithmetic operation, the value that is not a number type is converted to a number and a numeric comparison or operation is performed.

Number-to-character Conversions

  1. If a number (type INT, LONGINT, VASTINT) must be converted to a character string for use by a command or function (e.g., to be output by the LIST command or processed by $ substring), the number is converted and right-justified, always producing a result string long enough to hold the largest possible value for that data type (8 characters for INT; 12 characters for LONGINT; 17 characters for VASTINT).
  2. Number literals implicitly take the data type VASTINT and assume a number of decimal places equal to the number that actually appear in the literal. If the software has to convert a number literal to a character string for use by a command or function, it becomes a character string 17 characters long, as indicated in Rule 6.

Date Comparisons

  1. When two values are being compared, only one of which is type DATE, the other value is converted to DATE (if possible) and a DATE comparison is performed.
  2. If a number is converted to a date, it is assumed to be in a YYYYMMDD form (e.g., 19991122 is November 22, 1999).

Arithmetic Operations Involving Dates

  1. When an arithmetic operation is being performed on two values, at least one of which is type DATE, the operation is carried out as summarized below:
val1 + val2

If only one value is type DATE, the other is converted to a number and added (as a number of days) to the date.
If both values are type DATE, a normal arithmetic operation is performed and the result is treated as a number.

val1 – val2

If both values are type DATE, the dates are subtracted to yield the number of days between the two dates.
If val1 is type DATE and val2 is not, val2 is converted to a number (if necessary) and is subtracted (as a number of days) from the date.
If val2 is of type DATE and val1 is not, both values are converted to numbers (if necessary) and a normal arithmetic operation is performed.

val1*val2
val1/val2
val1^val2

Both values are converted to numbers (if necessary) and a normal arithmetic operation is performed.

Date-to-character Conversions

  1. If a DATE value must be converted to a character string, it becomes a string eight characters in length.

Explicit conversion Using Software Functions

Although values are implicitly converted from one data type to another as required, the software provides a number of functions that forcibly convert values from one data type to another.

The conversion functions are $ toalpha, $ tocharacter, $ todate and $ tonumber.

 

See Also

=, , >, >= (Condition)

About Conditional Expressions

Data Types and Storage of Values

Data Types and the Use of Database Indexes

How To Use Data Types

Was this article helpful?
0 out of 5 stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
5
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.

Leave a Reply

Your email address will not be published. Required fields are marked *

en_CAEnglish