Calculating Totals with Math Operations | XM Community
Solved

Calculating Totals with Math Operations

  • 11 November 2017
  • 4 replies
  • 10 views

Userlevel 3
Badge +1
I am calculating a total using math operations and storing a 6 or 7 digit number as embedded data. I want to display this to the respondent using piped text before they submit their survey. How can I add in commas/formatting so that instead of displaying "1357924" they see "$1,357,924"?
icon

Best answer by AnthonyR 14 November 2017, 00:24

View original

4 replies

Userlevel 4
Badge +5
I would like to know the answer to this question as well. When you add the piped text to a survey, you can stick "$" before the "${e://Field/InsertNameHere}", but formatting with commas, that's where you got me.
Userlevel 7
Badge +7
Unfortunately there is no built in method to handle this, but if you add an html span with an id of "number". You can use the following JavaScript added to the question to have it dynamically update the span with your number. This JavaScript assumes that the element you would like to pipe in is called "EDNumber" update appropriately for your situation:

Qualtrics.SurveyEngine.addOnReady(function()
{
var number = parseInt("${e://Field/EDNumber}")
$('number'). update(new Intl.NumberFormat().format(number));

});

Example html for the question:

`This is my number: <span id='number'></span>`

What's nice about this is that it will format numbers according to the locale of the respondents computer.
Userlevel 3
Badge +1
> @AnthonyR said:
> Unfortunately there is no built in method to handle this, but if you add an html span with an id of "number". You can use the following JavaScript added to the question to have it dynamically update the span with your number. This JavaScript assumes that the element you would like to pipe in is called "EDNumber" update appropriately for your situation:
>
> Qualtrics.SurveyEngine.addOnReady(function()
> {
> var number = parseInt("${e://Field/EDNumber}")
> $('number'). update(new Intl.NumberFormat().format(number));
>
> });
>
> Example html for the question:
>
> `This is my number: <span id='number'></span>`
>
> What's nice about this is that it will format numbers according to the locale of the respondents computer.

Thanks, this JavaScript did exactly what I was looking for.
When the ParseInt runs, it just pulls the integer piece of the number, and drops any info to the right of the decimal point. To work around that, I multiplied my embedded field by 100 in the survey flow, then pulled in that integer, and after pulling it into JS, dividing by 100 and working with that result.

Leave a Reply