Calculating Totals with Math Operations | XM Community
Skip to main content
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"?
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.
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.
> @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