Professional > Interview scripting > Writing interview scripts > Questions and responses > Questions with decimal responses
 
Questions with decimal responses
When a question requires a decimal number as a response, define it in the Metadata section of the interview script as:
Syntax
Qname "Text" double [[Values]];
Parameters
Qname
The question name.
Text
The question text.
Values
The numbers or range of numbers that will be accepted as valid responses. If you omit this parameter, the interviewing program will accept:
any negative value in the range:
‑1.79769313486232e308 to ‑4.94065645841247e−324
and any positive value in the range:
4.94065645841247e−324 to 1.79769313486232e308.
Specifying valid responses
You specify valid responses for decimal questions in the same way as for integer questions, so single values, fixed and open-ended ranges, lists of single values and ranges, and exclusive values are all acceptable. For more information, see Questions with integer responses.
Decimal responses are stored in the case data as double variables — that is, as 64-bit floating point values with 15 digits of precision. You can control the data format by specifying:
the number of decimal places to store in the case data
the number of characters to store for the number as a whole.
Decimal responses are stored in the case data as double variables; that is, as 64-bit floating point values with 15 digits of precision. You can control the data format by specifying:
the number of decimal places to store in the case data
the number of characters to store for the number as a whole.
Decimal point character
The character you use for the decimal point when specifying values depends on your computer’s locale/culture/language setting. For example, if your setting is en–UK you will use a dot (1.2, for example); if your setting is en–DA you will use a comma (1,2). The character that respondents must use depends on the language that the script sets for the interview or, if none is set, the language set for the respondent’s browser.
You can make the decimal point character independent of the interview language by specifying a language in the IOM.Locale property. The Locale property defines the language to use for data input and output and response validation. Normally, it is the same as the IOM.Language property, so if the language changes so does the locale. If you want all respondents to use the same character for the decimal point, you may specify a language that uses that character as the interview locale. For example, if you want all respondents to use a dot for the decimal point you may set IOM.Locale to English (en–us, for example). This overrides the language setting, so respondents may see questions and responses in French but they will still have to enter prices and similar values in the English format. (See also “Allowing a thousands separator character.)
Note Specifying the locale manually breaks the link between the two properties so any subsequent language changes do not affect the locale setting.
Number of digits to write
To specify the maximum number of digits that can be written, append the precision keyword to the standard question definition:
Qname "Text" double [[Values]] precision(NumDigits);
where NumDigits is the maximum number of digits.
In the following example, the weight will always be written as four digits.
Weight "What is your weight in kilograms?"
double [47.5..160] precision(4);
Number of decimal places
To specify the maximum number of decimal places that can be entered, append the scale keyword to the standard specification:
Qname "Text" double [[Values]] scale(NumDigits);
where NumDigits is the maximum number of decimal places.
In the following example, more than two decimal places cannot be entered for the price of the meal:
Cost "What was the total cost of the meal
  including service?"
double scale(2);
Allowing a thousands separator character
The interviewing program does not normally accept a thousands separator character in large numbers. For example, in countries that use the comma as the thousands separator, the number 1,512.89 will be rejected even if it is within the range specified for the question. If you want the interviewing program to accept thousands separators in numeric responses, place the following statement in the routing section of the questionnaire before the question is asked:
Qname.Validation.Options["AllowThousandsSeparator"] = True
where Qname is the name of a question with a numeric response.
The character that the interviewing program accepts as the thousands separator depends on the language or locale set for the interview. The language can be set in the script itself, otherwise it defaults to the language set in the respondent’s browser. This can be overridden by setting the interview’s locale in the script. The Locale property defines the language to be used for data input and output and for validation. For example, if the interview language is set to French, the interviewing program expects respondents to use a space as the thousands separator and a comma as the decimal point. If the script sets the locale to English, the interviewing program will then expect a comma for the thousands separator and a dot for the decimal point.
The Locale property normally mirrors the Language property so that when the language changes so does the locale. However, if you specify the locale manually this breaks the link between the two properties and any subsequent language changes do not affect the locale setting. For more information, see Using locale to control decimal number and date formats.
Note AllowThousandsSeparator is provided primarily to maintain backwards compatibility with early versions of the interview scripting language, in which the default was to require the use of thousands separator characters.
See also
Questions with categorical responses