Respondents are accustomed to seeing number grouping separators (commas in US English) when entering numbers greater than 1,000 in numeric text fields. Thus, it follows that survey designers sometimes request that separators are displayed in numeric questions where expected values could exceed three digits. To accommodate this need, Survey Programmers (SPs) can include the number format
and number locale
tags.
The
numberformat
tag allows SPs to create a type: text
(or number or integer) field in which numbers will automatically be displayed with grouping separators (e.g., commas in English) and can also allow or force a specified number of decimal places. Number formatting adds separators for visual clarity, and updates formatting as the respondent types out their response. The system-generated separators are not stored when the field is submitted so that the data saved is purely numeric. However, for easy of reference later in the survey interview, the formatted string value of a number format variable can be referenced with "_text" appended, like closed-ended variables. Open-end questions store a numeric value and a formatted string as originally entered by the responded (e.g., Arabic numerals or a numberformat
string), and they offer the SP access to both values.
- The numeric value is accessible via the standard '$Q1' reference format, e.g., 1234.56
- The formatted value is accessible via '$Q1_text', similar to closed-end questions' text values, e.g., '12.345,67€'
If the survey is being used for respondents from a country other than the United States, UK, or Australia, the number locale
tag can be applied with number format
to specify which country and locale-specific grouping separators, decimal signs, and currency symbols will be applied.
Try it!
Syntax
The following code block demonstrates the ways in which we can apply the number format
and number locale
tags. In r8.0+, the numberformat
tag can be used with the question types text, number, and integer.
# Example patterns that are supported: number format: 0 number format: 0,0 number format: 0,000 number format: 0,0[.]00 number format: 0,0.00 number format: 0.00 number format: 0[.]0 # Adding separators - decimals not permitted 1. Question requiring numerical input. type: text datatype: number numberformat: 0,0 # can also use 'datatype: whole' to force integer responses # Adding separators - decimals permitted 2. Question requiring numerical input. type: text datatype: number number format: 0,0.00 # the number of zeros after the decimal will dictate the place value this will round to # Switching the number format rules to another country's formatting style 3. Yep, it's another numerical input question type: text datatype: number numberformat: 0,0.00 numberlocale: fr # i.e., country code # See "Number Locale" example for more information # Adding currency symbol(s) and optional decimals 4. How much was spent? type: number number format: 0,0[.]00 {currency: y} number locale: fr # i.e., country code # brackets before decimal zeros indicates optionality [.]00
Tip: SPs should also consider the following when using numberformat
:
- The
numberformat
tag will accept inputs such as '#,#' or '#.##'. -
numberformat
will permit negative values as input. To restrict the input to positive values only, either usedatatype: whole
, or amin
orrange
tag (e.g.,range: >=0
). - The
numberformat
tag no longer supports inputs specifying optional trailing decimals such as '0.00[0]', although '0[.]00' (allowing for whole or decimal input) is still supported. Additionally, including a dollar sign is no longer permitted in the input, and users should instead include thecurrency: y
decorator. See below for additional information.
Tags
The following tags are commonly used with numberformat
.
Tag | Description |
---|---|
datatype
|
Specifies which response type is accepted. Options include:
Note: Users may want to apply a |
maxlen
|
Specifies the max number of characters a respondent can enter. For numerical input, the value inputted would indicate the max size of the response (e.g., maxlen: 3 would accept a max input of '999'). |
size |
Specifies the size (in ems) of the response text input. |
range |
Can be used in place of maxlen ; specifies the accepted response range.
|
prefix |
Specifies text or a symbol to be shown before the respondent text field. |
postfix |
Specifies text or a symbol to be shown after the respondent text field. |
numberlocale |
Specifies a language/locale code to alter the number formatting for countries outside of the US. When combined with the currency: y decorator, that country's currency symbol will also be applied. |
Note: HTML for "non-breaking space" (
) can be added to accommodate a needed space after and before the prefix
and postfix
tags, respectively.
Decorators
The following decorators can be used along with numberformat
. When including multiple decorators, each should be in their own set of curly braces – e.g., numberformat: 0,0 {delay: 250} {currency: y}
.
Decorator | Description |
---|---|
currency |
Accepts 'y' (yes) and 'n' (no) inputs; when set to 'y', adds currency formatting and symbol to respondent input. When combined with SPs can still use the |
delay |
Specifies the amount of time in msec to wait before adding formatting to respondent input; defaults to '500'. Users can specify delay: 0 if they want the separators added immediately. |
Accepted locales
The number locale
tag can be used with number format
. It accepts the following CLDR standardized locale codes. SPs should note that locales with a short code alternate can use the shorter code.
Language/Locale Code | Short Code Alternate | Description |
Example Formatting (Currency, Grouping, & Decimal Signs) |
---|---|---|---|
bg | bg | Bulgarian | 12 345,67лв. |
cs-CZ | cs | Czech | 12 345,67Kč |
da-DK | da | Danish | 12.345,67kr |
de-AT | German - Austria | €12 345,67 | |
de-CH | German - Switzerland | 12'345.67CHF | |
de-DE | de | German - Germany | 12.345,67€ |
de-LI | German - Liechtenstein | 12'345.67CHF | |
el | Greek | 12.345,67€ | |
en-US | en | English - United States | $12,345.67 |
en-AU | English - Australia | $12,345.67 | |
en-GB | English - Great Britain | £12,345.67 | |
en-IE | English - Ireland | €12,345.67 | |
en-NZ | English - New Zealand | $12,345.67 | |
en-US | English - United States | $12,345.67 | |
en-ZA | English - South Africa | R12 345,67 | |
es-AR | Spanish - Argentina | 12.345,67$ | |
es-CL | Spanish - Chile | $12.345,67 | |
es-CO | Spanish - Colombia | 12.345,67€ | |
es-CR | Spanish - Costa Rica | 12 345,67₡ | |
es-ES | es | Spanish - Spain (Traditional) | 12.345,67€ |
es-MX | Spanish - Mexico | 12,345.67$ | |
es-NI | Spanish - Nicaragua | C$12,345.67 | |
es-PE | Spanish - Peru | S/.12,345.67 | |
es-PR | Spanish - Puerto Rico | $12,345.67 | |
es-SV | Spanish - El Salvador | $12,345.67 | |
et-EE | et | Estonian | 12 345,67€ |
fa-IR | fa | Farsi | ﷼12٬345.67 |
fi-FI | fi | Finnish - Finland | 12 345,67€ |
fil-PH | Filipino | ₱12,345.67 | |
fr-CA | French - Canada | 12 345,67$ | |
fr-CH | French - Switzerland | 12 345.67CHF | |
fr-FR | fr | French - France | 12 345,67€ |
he-IL | he | Hebrew - Israel | ₪12,345.67 |
hu-HU | hu | Hungarian | 12 345,67Ft |
id | Indonesian | Rp12.345,67 | |
it-CH | Italian - Switzerland | CHF12'345.67 | |
it-IT | it | Italian - Italy | 12.345,67€ |
ja-JP | ja | Japanese | ¥12,345.67 |
ko-KR | ko | Korean | ₩12,345.67 |
lv-LV | lv | Latvian - Latvia | 12 345,67€ |
nb | Norwegian Bokmål | kr12 345,67 | |
nb-NO | Norwegian - Norway | 12 345,67kr | |
nl-BE | Dutch - Belgium | 12 345,67€ | |
nl-NL | nl | Dutch - Netherlands | €12.345,67 |
nn | Norwegian Nynorsk | 12 345,67kr | |
pl-PL | pl | Polish - Poland | 12 345,67 zł |
pt-BR | Portuguese - Brazil | R$12.345,67 | |
pt-PT | pt | Portuguese - Portugal | 12 345,67€ |
ro-RO | ro | Romanian | 12.345,67 lei |
ru-RU | ru | Russian - Russia | 12 345,67руб. |
ru-UA | Russian - Ukraine | 12 345,67₴ | |
sk-SK | sk | Slovak | 12 345,67€ |
sl | Slovenian | 12.345,67€ | |
sr-Cyrl-RS | Serbia - Cyrillic | 12.345,67RSD | |
sv-SE | sv | Swedish - Sweden | 12 345,67kr |
th-TH | th | Thai | 12,345.67฿ |
tr-TR | tr | Turkish | 12.345,67₺ |
uk-UA | uk | Ukrainian | 12 345,67₴ |
zh-CN | zh | Chinese - China | ¥12,345.67 |
zh-MO | Chinese - Macau SAR | MOP12,345.67 | |
zh-SG | Chinese - Singapore | $12,345.67 | |
zh-TW | Chinese - Taiwan | NT$12,345.67 |
Examples
Adding separators
To specify that separators should appear, use a '0,0' or '#,#' input. Note that attempting to add a decimal will be ignored by the system (e.g., entering "2.65" will appear as "265" in the text field).
The size
tag can always be applied to control the width of the text field, especially in the case of questions that allow for decimal responses where default text field sizing specified via the range
or maxlen
tags will be ignored.
Note: If there is even a modest probability that the respondent will enter currency in a format such as "34.00", use number formats such as '0,0.00' or '0.00'.
Adding decimals
If the type: text
field allows decimals (i.e. datatype
is not restricted to 'whole') and number format
is used, it must be instructed to accommodate them by including a decimal and the number of decimal places to accept after it.
The above example automatically enters a decimal for the respondent. Respondents can theoretically enter as many digits as they want to the left of the decimal. Two digits will remain static to the right of the decimal without the need to round to the nearest hundredth (.01). The comma separator appears in real-time as the field is being used.
To enter a decimal value, click to the right of the decimal place, and the tenths (0.1) and hundredths (.01) place values may be edited.
In r8.0+, the question types 'integer' and 'number' can be used instead of using type: text
with the datatype
tag. Q1B can instead be coded as follows. SPs should note that both type: number
and type: integer
do allow for negative values, so specifying minimums or ranges may be necessary; both question types can be overridden with the datatype
tag as well.
Optional decimals and decimal units
To allow respondents to enter decimals, but not automatically add the digits and decimal point (if respondents do not add the decimals themselves), use square brackets around the decimal point.
In the above example, a respondent input of "401.10" will be preserved, and a response of of "401.1" will be formatted as "401.10". On the other hand, a respondent input of "102" will not be formatted as "102.00" as the decimal places are optional.
Currency prefixes
It is possible to use number format
to prefix a currency character to the text entered in the field. To do so, include the currency: y
decorator or use the prefix
tag. When entering a value, the dollar sign will automatically appear in the text field. The size
tag has been applied here to specify a more reasonable size to the text field.
Specifying a min/max value
SPs may specify minimum and maximum values via either the min
and max
tags, or via the range
tag. The following table uses the range
and sct
(showcolumntotal
) tags to specify that the respondent inputs only values between $0 and $60. No restriction on the total is required as the range
specifications dictate each row's input be at most 60.
In r8.0+, the above SCT example can instead be coded using type: number table
or type: integer table
instead of having to use a text table with the datatype
tag.
Piping responses with the cell tag
In the following example, responses from T29 are piped into T30 to compare their previous quarter's sales (T29) to their sales results for this quarter, and what they anticipate for the next/upcoming quarter. Whether the '$' is specified with the prefix
tag or via the currency
decorator does not matter, but note that the prefix will not be applied to the piped in responses in T30 and must be specified instead in the {text: }
decorator.
Responses that are piped into a follow up table using the cell
tag do not appear in reports for the follow up table. If using the cell
tag in a situation like the previous example, be sure to let clients know that this will be the case.
number_locale
Different languages and regions use different standards for numeric separators and decimal points. To use non-US standards, include the
number locale
tag. The currency
decorator has been included to make sure the proper currency formatting for Germany and Bulgaria is applied to the respondent's input.
In r8.0+, using $QX_text
can be used to display the formatted numerical input (e.g., what was displayed after the currency based on number locale
was applied) and $QX
can be used to display the actual inputted response.
Comments
0 comments
Please sign in to leave a comment.