toNumber
toNumber is a method you can use to convert the value of a question from a string into a Number (double) (go to Floating-point Data for more information):
f(qID).toNumber()qID is the question ID.
Note: The toNumber method requires that the question is answered, and that the value stored for the question can be converted to a number. If not, it will return NaN (not a number).
toInt
toInt is a method you can use to convert the value of a question from a string into an integer(go to Integers for more information):
f(qID).toInt()qID is the question ID.
Note: The toInt method requires that the question is answered, and that the value stored for the question can be converted to an integer. If not, it will fail, terminate the interview with an “Internal server error” and send an error report to the “Email address to receive emails triggered by scripting errors in interview”. The method should either only be used when you know that there will always be a valid response to the question, or you should check that the response is numeric before using toInt (for example using IsInteger).
toDecimal
toDecimal is a method you can use to convert the value of a question from a string into a decimal(go to Floating-point Data for more information):
f(qID).toDecimal()qID is the question ID.
Note: The toDecimal method requires that the question is answered, and that the value stored for the question can be converted to a Decimal. If not, it will fail, terminate the interview with an “Internal server error” and send an error report to the “Email address to receive emails triggered by scripting errors in interview”. The method should either only be used when you know that there will always be a valid response to the question, or you should check that the response is numeric before using toDecimal (for example using IsNumeric).
Screening on a Numeric Question
Let us say you have a survey with an initial numeric question age. In this question you ask for the respondent's age. For this survey you have defined a target: Persons between 18 and 35. To make a condition for your screening, you have to use toNumber to convert the answer from a string into a number. You may then make an expression like this in the condition:
f("age").toNumber() < 18 || f("age").toNumber() > 35Note: Always use toNumber, toInt or toDecimal when you use expressions involving the operators <,<=,>= or >, or when doing arithmetic operations on the answers.
toBoolean
toBoolean is a method that converts the variable into a Boolean (true/false). It can be used to check if a question has been answered, or for a single question with the Boolean property, if it has been answered with the true or false answer alternative.
Note: The Boolean question property mentioned in the last sentence above is only available in surveys using the Optimized Database format.
f(qID).toBoolean()If the respondent has answered the question with question ID qID, the expression will yield true, if not, false. Or, if qID is a Boolean question, the expression will yield true if the respondent has chosen the answer corresponding to true (1), and false if the respondent has chosen the answer corresponding to false (0)
You have already seen toBoolean used in the Removing an Answer in a Single or Grid Question example.
toDate
toDate can be used on date questions to return a structure representing the selected date value. This is based on the .Net Date object, and is not necessarily the same as the JavaScript or JScript Date object, so it may be necessary to create a new Date object instead for scripting purposes.
f(qID).toDate()returns a strongly-typed Nullable DateTime object representing the date answered.
day
day can be used on date questions to get the day part of the specified date.
f(qID).day()returns the integer value (1 - 31) representing the day part of the specified date. 0 is returned if no date is specified.
month
month can be used on date questions to get the month part of the specified date.
f(qID).month()returns the integer value representing month part of the date specified, 0 if no date is specified. Conventional numbering of months is used (1 = January, 2 = February etc.).
year
year can be used on date questions to get the year part of the specified date.
f(qID).year()returns the integer value representing year part of the date specified, 0 if no date is specified.
datestring
datestring can be used on date questions to get a textual representation of the specified date.
f(qID).datestring()returns the textual representation of the chosen date in accordance to the current language setting (for example, English gives "Friday, April 25, 2010"). The same result will be achieved (a textual representation of the date in accordance with the current language setting) when performing response piping on a date question.
Note: The date question type is only available in surveys using the Optimized database format.