int, double, bool. Transforming objects into numbers or bool

^name.int[]
or
^name.int(default)
^name.double[]
or
^name.double(default)
^name.bool[]
or
^name.bool(default)


The method transforms value of variable
$name into either integer or real number or bool respectively and returns it. If real number is transformed into integer, it will be truncated.

One may also specify default value, which will be returned if transformation is impossible. Default value may be used when you process data received from visitors interactively. It will prevent text values from appearing in mathematical expressions, when a user inputs, for example, a string instead of a number initially expected.

Important notice: empty string or a string containing "white spaces" only (space characters, tab characters, or new line characters) is regarded as zero.

Example
Code…

$str[Item]
^str.int(1024)


…will output number
1024, as object str cannot be transformed into object of class int.

Code…

$double(1.5)
^double.int[]


…will output number
1, as the number was truncated.


Code...
^if(^form:search_in_text.bool(false){
   
...searching in text...
}



Copyright © 1997–2010 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 05.02.2008