Type Conversion
WMLScript operators implicitly convert their
operands into the types they require. For example, the
*
operator for multiplication can operate on
either integers or floating points, so the operands must first be
converted into one of these types.
If an argument can’t be converted, the result is
invalid
. Note that there are no explicit
conversions to invalid
, since no operator actually
requires an invalid
value.
Conversion to String
Integers convert to a string representing their value in decimal. For example, the integer
1234
converts to the string"1234"
, and the integer-42
converts to the string"-42"
.Floating-point numbers convert to a string representing their value. The exact form of this string may differ from implementation to implementation. For example, the floating-point number
0.2
may convert to any of the strings"0.2"
,"2e-1"
,".2"
,"0.2e+0"
, and so on.Boolean
true
is converted to the string"true"
, and Booleanfalse
is converted to the string"false"
.invalid
can’t be converted to a string.
Conversion to Integer
A string containing a valid decimal integer is converted into that integer. Any other string can’t be converted to an integer. For example, the strings
"1234"
and"+1234"
both convert to the integer1234
, but the string"1234x"
can’t be converted.No floating-point value can be converted to an integer.
Boolean
true
is converted to1
, and Booleanfalse
is converted to0
.invalid
can’t be converted to an integer.
Conversion to Floating-Point Number ...
Get Learning WML, and WMLScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.