Type Casts

The macro language is not strongly typed and data will automatically be converted as needed for an operation. For example, the following lines have the same effect:

$var += 1

$var += “1”

However, in some cases you may want to cast/change the data type of a particular variable. To do this you use a type cast command that returns a converted form of its argument.

Cast to Int value, [round] v1.0.1

Returns an integer from the given value. If the value is textual then the number at the start of the string is used, ignoring any whitespace. If there is no number at the start of the text, returns zero.

The second argument optionally specifies what happens when a decimal/float number is encountered. If the argument is true, then the float is rounded to the nearest integer (eg: 1.6 becomes 2), otherwise the decimal is truncated to discard the fraction (eg: 1.6 becomes 1). The default is to round.

Cast to Float value v1.0.1

Extracts a floating point (decimal) value from the given value. If the value is textual then the number at the start of the string is used, ignoring any whitespace. If there is no number at the start of the text, returns zero.

Cast to String value, [smartConvert] v1.0.1

Returns the given value converted to plain text (eg: any formatting is discarded).

The second argument optionally specifies whether the conversion is smart. If the argument is true then complex content that otherwise would be lost (eg: footnotes, tables) will be replaced with a plain string representation. A false value indicates the content should be discarded. By default the conversion is smart.

Cast to Attributed String value v1.0.1

If the input value is already attributed then no change is made. Otherwise the result is an attributed string that has no attributes applied, eg: the corresponding Attributes object has the @undefined value for all values.


Previous Chapter
Type Commands
<<  index  >>
 
Next Chapter
Control Flow