Converting Primitive Types
You can convert any variable of a primitive type to another primitive type, by using the following syntax.
expression.primitive-type
The following example shows the conversion of a
writeDate(date: Date); begin write "The date is " & date.String; end;
As the changing of collection membership of primitive types is not supported by the reorganization process, a warning message is displayed when a collection membership of primitive types is changed from one primitive type to another and the class is already marked for reorganization or the change will cause the class to be marked for reorganization.
Converting any primitive value to a
The following example shows an
vars i : Integer; begin i := 10; write i.Real; //outputs 10 write i.Binary.Real; //outputs 4.94065645841247e-323 Not recommended end;
The following table lists the effect of converting to the
From | To Byte | To Character |
---|---|---|
Binary | The first byte is copied. | In a Unicode system, the first two bytes of the Binary are taken as a Character (null‑padded, if necessary). In an ANSI system, the first byte of the Binary is taken as a Character. |
Boolean |
If true, the character is converted to 1; false is converted to zero (0). |
If true, the character with ANSI or Unicode value equal to 1; if false, the Character with ANSI or Unicode value equal to zero (0). |
Byte | No change. | Character with ANSI or Unicode value equal to the value of the Byte. |
Character | Numeric value in the range zero (0) through 255. If the value of the Character in a Unicode system is outside this range, an exception is raised. | No change. |
Decimal |
Numeric value, truncated if necessary. If the resulting Byte value is outside the range zero (0) through 255.9999, an exception is raised. |
Character with ANSI or Unicode value equal to the integer part of the number. If the resulting Character value is outside the range -255 through 255 ANSI, an exception is raised. For Unicode, the range that can be converted is zero (0) through 65535.9999, with no exception being raised. |
Integer and Integer64 | Numeric value (an exception is raised if the value exceeds the maximum size of the target). |
Character with ANSI or Unicode value equal to the number. If the resulting Character value is outside the range zero (0) through 255 ANSI or the range zero (0) through 65535 Unicode, an exception is raised. |
Real |
Numeric value, truncated if necessary. If the resulting Byte value is outside the range zero (0) through 255, an exception is raised. |
Character with ANSI or Unicode value equal to the integer part of the number. If the resulting Character value is outside the range zero (0) through 255 ANSI or the range zero (0) through 65535 Unicode, an exception is raised. |
String and StringUtf8 |
Numeric value represented by the string of digits. Only US‑ASCII characters in the range zero (0) through 9 are recognized. The string can contain an optional string of tab and space characters, an optional sign, or a string of numeric values. The first unrecognized character ends the conversion. If the string cannot be converted to a numeric value, JADE returns zero (0), as shown in the following examples. "abc".Byte = 0 "12abc".Byte = 12 Overflow exceptions occur if the result of the conversion is too large. Use the |
First character. |
The following table lists the effect of converting to the
From | To Boolean |
---|---|
Binary | If all bits in the first byte are zero (0), then false; else true |
Boolean | No change |
Byte | If all bits are zero (0), then false; else true |
Character | If null, then false; else true |
Date | If null, then false; else true |
Decimal | If zero (0), then false; else true |
Integer and Integer64 | If zero (0), then false; else true |
Real | If zero (0), then false; else true |
String and StringUtf8 | If "true", then true; else false |
Time | If null, then false; else true |
TimeStamp | If null, then false; else true |
TimeStampInterval | If null, then false; else true |
TimeStampOffset | If null, then false; else true |
The following table lists the effect of converting to the
From | To String and StringUtf8 |
---|---|
Binary | A direct binary copy is made, which when converted to a StringUtf8, may result in an illegal byte sequence. |
Boolean | true is converted to "true"; false is converted to "false". |
Byte | Binary value of the Byte in a decimal format. |
Character | One-character string. |
Date | Date in the format dd MMMM yyyy. If the receiver has the invalid value, the string is "*invalid*". If the receiver is zero (0), an empty string is returned. The resulting string is always limited to ASCII digits and characters, it is never locale‑sensitive, and English month names are used. |
Decimal | Decimal number formatted to the required number of decimal places. |
Integer and Integer64 | Integer value. |
MemoryAddress | Memory address in a hexadecimal number format. |
Point | Cartesian coordinates in the format x,y. |
Real | Number displayed in expanded form. |
String and StringUtf8 | Typecasting assumes that the string to be converted contains ASCII characters only. Use the asString and asStringUtf8 methods for conversions based on a locale in an ANSI system. |
Time | Time in the format hh:mm:ss. |
TimeStamp | Date and time in the format dd MMMM yyyy, hh:mm:ss. |
TimeStampInterval | Timestamp interval in the format d:hh:mm:ss.fff. |
TimeStampOffset | Timestamp offset in the format d:hh:mm:ss.fff +|-hhmm. |
The following table lists the effect of converting to the
From | To Integer and Integer64 |
---|---|
Binary | First 4 or 8 bytes are copied as the Integer or Integer64 result, respectively. If the Binary value has fewer than 4 bytes or 8 bytes, the converted result is padded with null bytes. |
Boolean | true is converted to 1; false is converted to zero (0). |
Byte | Numeric value in the range zero (0) through 255. |
Character | Numeric value in the range zero (0) through 255 for an ANSI system, or zero (0) through 65,535 for a Unicode system. |
Date | Julian day number for Integer and Integer64. |
Decimal | Numeric value, truncated if necessary. |
Integer and Integer64 |
Numeric value (an exception occurs if the value exceeds the maximum size of the target type). |
Real |
Numeric value (an exception occurs if the value exceeds the maximum size of the target type). |
String and StringUtf8 |
Numeric value represented by the string of digits. Only US-ASCII characters in the range zero (0) through 9 are recognized. The string can contain an optional string of tab and space characters, an optional sign, or a string of numeric values. The first unrecognized character ends the conversion. If the string cannot be converted to a numeric value, JADE returns zero (0), as shown in the following examples. "abc".Integer = 0 "12abc".Integer = 12 Overflow exceptions occur if the result of the conversion is too large. Use the |
Time | Milliseconds since midnight for Integer and Integer64. |
The following table lists the effect of converting to the
From | To Decimal and Real |
---|---|
Binary | Sufficient bytes are copied to the Decimal or Real result (padded with null bytes, if necessary). The result of the conversion may not be meaningful. |
Boolean | true = 1, false = 0. |
Byte | Numeric value in the range zero (0) through 255. |
Character | Numeric value in the range zero (0) through 255 for an ANSI system, or zero (0) through 65,535 for a Unicode system. |
Date | Julian day number. |
Decimal | Numeric value. |
Integer and Integer64 | Numeric value. |
Real | Numeric value. |
String and StringUtf8 |
Numeric value. Only US‑ASCII characters in the range 0 through 9 are recognized. The string can contain an optional string of tab and space characters, an optional sign, or a string of numeric values. The first unrecognized character ends the conversion. If the string cannot be converted to a numeric value, JADE returns zero (0), as shown in the following examples. "abc".Real = 0 "1.2abc".Decimal = 1.2 If you are uncertain of the contents of a string, call the |
Time | Milliseconds since midnight. |
The following table lists the effect of converting to the
From | To Date | To Time |
---|---|---|
Binary | First 4 bytes are copied as the Date value. If the Binary value has fewer than 4 bytes, null bytes are used for padding. The result of conversion may not be meaningful. | First 4 bytes are copied as the Time value. If the Binary value has fewer than 4 bytes, null bytes are used for padding. The result of conversion may not be meaningful. |
Date | No change. | Not permitted. |
Decimal | Julian day number is converted to Date. | Milliseconds since midnight is converted to Time. |
Integer and Integer64 | Julian day number is converted to Date. | Milliseconds since midnight is converted to Time. |
Real | Julian day number is converted to Date. | Milliseconds since midnight is converted to Time. |
String and StringUtf8 | Valid date string is converted to Date. |
|
Time | Not permitted. | No change. |
TimeStamp | Date part copied, Time part discarded. | Time part copied, Date part discarded. |
When casting a string to a date, the following rules apply.
-
The String must contain the date elements in one of the following orders.
-
<day><month><year>
-
<month><day><year>
-
<year><month><day>
-
-
The delimiter between date elements is a sequence of one or more non‑alphanumeric characters.
-
The day and year elements must be numeric. If the month element is not numeric, it must be a short (three‑character) or long English month name (case‑insensitive).
-
If the year element is one or two digits, it is assumed to be from the current century.
-
If the first element is numeric, it is assumed to be a year if it has:
-
Four or more digits
-
Two or more digits and the first separator begins with a colon (:)
-
When casting a string to a time, the following rules apply.
-
The delimiter between time elements is a single non‑alphanumeric characters.
-
The hour element must be numeric in the range 0 through 24 (inclusive).
-
The minute and second elements must be numeric in the range 0 through 59 (inclusive).
-
The millisecond element must be numeric in the range 0 through 999 (inclusive).
-
A term specifying pre- or post-noon (that is, case‑insensitive "am", "a.m.", "pm", or "p.m.") is valid only if the hour element is less than or equal to 12.
-
"12:00 a.m.".Time converts to 00:00:00.
-
"12:00 p.m.".Time converts to 12:00:00.
The following table lists the effect of converting to the
From | To TimeStamp | To TimeStampInterval |
---|---|---|
Binary | First 8 bytes are copied as the TimeStamp value. If the Binary value has fewer than 8 bytes, null bytes are used for padding. Result of conversion may not be meaningful. | First 8 bytes are copied as the TimeStampInterval value. If the Binary value has fewer than 8 bytes, null bytes are used for padding. Result of conversion may not be meaningful. |
Date | Date copied, Time null. | Not permitted. |
String and StringUtf8 | Date and Time string converted to TimeStamp. | In the format ddd:hh:mm:ss.fff. |
Time | Date null, Time copied. | Not permitted. |
TimeStamp | No change. | Not permitted. |
TimeStampInterval | Not permitted. | No change. |