This is an old revision of the document!
Table of Contents
sliderNumFormat - Format slider scale and value numbers
The sliderNumFormat function formats scale numbers (above the sliders) and values (appear when you drag a slider). It allows scale and value formats to be the same or different. The function uses Intl.NumberFormat to format numbers in a variety of styles based on locale or locales. Some of the possibilities include:
- Thousands separators (e.g., 1,000)
- Decimals (e.g., 1,000.00)
- Currency (e.g., $1,000)
- Percents (e.g., 100%)
- Units (e.g., 16 l, 16l, or 16 liters)
- Scientific (e.g., 1.000E3)
- Compact (e.g., $1K)
Here is a simple example:
This function is available for a reasonable fee. Contact TomG on the Qualtrics Community to learn more.
Set-up Instructions
Add Function To Survey
Add the sliderNumFormat function to the survey header to make it available to any question in the survey. Go to Look & Feel → General → Header edit →
and paste the provided sliderNumFormat function JS:
<script>/*Paste sliderNumFormat function JS here*/</script>
Alternatively, paste the sliderNumFormat function JS into a question's JS outside the existing Qualtrics functions to make it available to questions on the page.
JavaScript Function Call
Add JS to call the sliderNumFormat function to apply it to the Slider question as follows:
Qualtrics.SurveyEngine.addOnload(function() {
sliderNumFormat(this);
});
To override the default options, specify the desired options in the second function argument as an object. For example:
Qualtrics.SurveyEngine.addOnload(function() {
sliderNumFormat(this,{format:{style:"currency",currency:"USD",maximumFractionDigits:0}});
});
Options
format
format is a object used to specify the Intl.NumberFormat formatting options. The format is exactly the same as that used by the Intl.NumberFormat options object. format applies to both scale and value numbers.
Default: {} (empty, use Intl.NumberFormat defaults)
locale
locale is a string or array that specifies the locale or locales to be used by Intl.NumberFormat.
Default: "en-US"
valueFormat
valueFormat is an object that specifies the Intl.NumberFormat formatting options for value numbers. The format is exactly the same as that used by the Intl.NumberFormat options object. If the same option is included in the format option the valueFormat option takes precedence.
Default: {}
scaleFormat
scaleFormat is an object that specifies the Intl.NumberFormat formatting options for scale numbers. The format is exactly the same as that used by the Intl.NumberFormat options object. If the same option is included in the format option the scaleFormat option takes precedence.
Default: {}
