%num() Function

Top  Previous  Next

%num() function is used to convert the result of the given expression to a number. We already know that if the given parameter is a symbol we can use data type specifier 'n:' in front of the symbol name for the same purpose, but that wouldn't work if the parameter is an expression.

Syntax:

%num(expression [, default-number])
 

expression

The expression whose result is subject for conversion.

default-number

The default value to return, in case of the expression result cannot be converted to a number. This parameter is optional and if omitted and if the result cannot be converted to a number an CScript exception occurs.

 

 Expression Result

 Returned Value

 '' or 'false' or 'False'

 0

 'true' or 'True'

 1

 A Valid Number

 The Number

 An Invalid Number

 The Default Number

 

Examples:

%doif( num(PRICE,100) > MAXPRICE)

  ...

%doend()

 

%set( A, num(sstr(B,1,2)) * 2 )