Professional > Interview scripting > Writing interview scripts > Displaying information on a page > Text substitution > Formatting substituted values
 
Formatting substituted values
When the interviewing program makes substitutions, it inserts the values exactly as they are defined in the script or as the respondent typed them. When you display something that the respondent typed, you can change the formatting so that, for example, a cost value is always displayed with a currency symbol and two decimal places, or a text value is always displayed with the first letter in upper case and the rest in lower case. You do this by following the name of the question or substitution marker with a colon and a formatting code.
Syntax
{#Qname:fmt} or {@Marker:fmt} or {InsertName:fmt}
(Remember that the # version is for ordinary questions, and the @ version is for loops.) You can use any formatting code that the UNICOM Intelligence Format function supports, but the ones that you will find most useful are listed here.
Decimal numbers
If the substituted value is a decimal number (for example, the response to a question whose type is double), you can specify the number of decimal places to be displayed. The character used for the decimal point (dot or comma) is determined by the setting of the IOM.Language or IOM.Locale property in the script or, if this is undefined, by the language of the respondent's browser.
These properties also control the character displayed for the thousands separator: a comma is used for languages such as English that normally use a comma, and a space is used for countries such as France and Germany that normally use a dot. However, displaying examples of numbers that use a thousands separator may be confusing for respondents when the interview scripting language normally requires responses to be entered without this character. For more information, see Allowing a thousands separator character.
Methods of formatting decimal values are shown below and are based on the response Interest=15.8241 and Cost=50870.
Substitution marker
Produces
{#Interest:f2.3}
15.825 or 15,825 depending on the browser setting. Rounding is always away from zero.
{#Interest:f2.0}
15 for all respondents.
{#Cost:f2}
50870.00 or 50870,00 depending on the browser setting. The number of decimal places shown depends on the default for the locale. Decimal values are padded with zeroes to reach the required number of decimal places.
{#Cost:n}
50,870.00 for a respondent running a UK English browser, or 50 870,00 for a respondent in, say, France, where the decimal separator is a comma and the thousands separator is a dot.
Currency
If the substituted value is a currency value, you can use the c formatting code to have it displayed with a currency symbol and a set number of decimal places. The currency symbol and format are determined by the setting of the IOM.Language or IOM.Locale property in the script or, if this is undefined, by the language of the respondent's browser. For more information about the relationship between language and locale, see Using locale to control decimal number and date formats.
To control the number of decimal places displayed, follow c with the number of decimal places required. If the respondent's answer has fewer decimal places, the interviewing program pads the answer with zeroes at the end to reach the specified length. If the answer has more decimal places, the interviewing program rounds the answer to the nearest two places, rounding away from zero in borderline cases. Examples based on responses of Cost=26 and Interest=15.8245 are as follows:
Substitution marker
Produces
{#Interest:c}
£15.8245 for a respondent running a UK English browser, $15.8245 for a respondent running a US English browser, or 15,8245€ for a respondent in, say, France, where the currency is euros and the decimal separator is a comma.
{#Cost:c0}
$26 or the equivalent for non US-English browsers.
{#Cost:c2}
$26.00 or the equivalent for non US-English browsers.
{#Interest:c2}
$15.83 or the equivalent for non US-English browsers (15,83€ for a French browser, for example).
Dates and times
If the substituted value is a date and/or time, you can display just the date, just the time, or both, and you can choose the format in which it is presented. The underlying date format is determined by the setting of the IOM.Language or IOM.Locale property in the script or, if this is undefined, by the language of the respondent's browser. Available formats are shown in the table and are based on an answer of Birth=2:10pm 4 September 1956:
Substitution marker
Produces
{#Birth:d}
or
{#Birth:D}
A date in the format specified by the respondent's browser; for example, 04/09/1956 or 04 September 1956 in a UK English browser and 09/04/1956 or Tuesday, September 04, 1956 in a US English browser. If the year is omitted the current year is assumed.
{#Birth:t}
or
{#Birth:T}
A time in the format specified by the respondent's browser; for example, 14:10:00 or 2:10PM. If there is no time specified, midnight (00:00:00) is assumed.
{#Birth:f}
or
{#Birth:F}
A date and time in the format specified by the respondent's browser; for example, 04 September 1956 14:10:00 (or 2:10:00 PM) in a UK English browser or Tuesday, September 04, 1956 2:10 PM in a US English browser
Text
If the substituted value is text that the respondent has typed, you can change the case in which it is displayed. In the examples that follow, Flavor=Peach and Pineapple and OtherFlavor=apricot and mango.
Substitution marker
Action
Produces
{Flavor:l}
(lowercase L)
Lowercase first letter of text
peach and Pineapple
{Flavor:L}
Lowercase the whole text
peach and pineapple
{OtherFlavor:u}
Uppercase first letter of text
Apricot and mango
{OtherFlavor:U}
Uppercase the whole text
APRICOT AND MANGO
{OtherFlavor:w}
Title case the first word (that is, uppercase first letter and lowercase all others)
Apricot and mango
{Flavor:W}
Title case all words
Peach And Pineapple
Categorical responses
When the interviewing program reads {#Qname} and Qname is the name of a categorical question, it displays the labels of the answers chosen for that question exactly as they are defined in the script. If you want to change the way in which the texts are displayed (for example, to display them in lowercase when they have been defined in mixed‑case), you must use two formatting codes, one that picks up the label text and the other that defines the format required. The two codes must be separated by a semicolon. The code that picks up the response label is b, so the general syntax for formatting categorical response texts is:
{#Qname:b;code}
For example, if the question is defined as:
Job "What is your position in your company?" categorical [1..1]
{
IntScriptwriter" Interview scriptwriter",
SMScriptwriter "Sample management scriptwriter",
SysAdmin "System administrator",
PhoneSupervisor "Phone room supervisor",
ProjMan "Project manager",
Interviewer, Coder
};
the reference
{#Job:b;L}
displays the respondent's answer all in lower case; interview scriptwriter or system administrator, for example.
Response labels are treated as texts, so you can use any formatting character that is valid for texts, as described earlier in this section. For example:
{#Job:b;U}
to display the respondent's job title all in uppercase.
See also
Text substitution