Please enable JavaScript to view this site.

ESL Documentation

Navigation: ESL Documentation > ESL Programmers Guide > ESL Language Elements > Type Conversions

String/Integer and String/Floating Point Conversions

Scroll Prev Top Next More

ESL will convert string values to integer or floating point values, and vice versa. Therefore, you can provide a string value in any statement in which an integer or floating point value is required, and vice versa. The following are valid specifications:

 

string variable Pos is "50"

 

disabled key Stop at position Pos Pos

    draw to Pos 50

 

When a string contains only digits, ESL converts it to integers or floating point values in the obvious way ("50" is converted to 50; "50.01" is converted to 50.01). When the string contains blanks or alphabetic or special characters, ESL starts at the beginning of the string and proceeds according to the following rules:

 

It ignores any leading blanks.

 

It examines the first non-blank character(s) in the string. For integers, if the characters are digits (optionally preceded by a minus sign), ESL interprets the value as being an integer. For floating point values, if the string contains a decimal point, the digits before the decimal point and after the decimal point up to the first non-digit are regarded as the floating point value.

 

It terminates at the first character that is not a digit (or decimal point, for floating point values). If it terminates before locating a number, the value is zero.

 

The following are some sample conversions:

 

String

to Integer

"52"

52

"-52"

-52

" 52"

52

"52X5"

52

"5 2"

5

"X52"

0

 

String

to Floating Point

"52.5"

52.50

"-52.5"

-52.50

" -52.5"

-52.50

"52.5.1"

52.50

"52 5"

52.00

".52"

0.52

"-.52"

-0.52

 

As mentioned earlier, ESL will not perform conversions inside expressions; therefore, you cannot specify string values as operands for arithmetic operators. For example:

 

(Pos / "10")

 

is invalid.