Formatting Embedded Data with comma separators? | XM Community
Skip to main content
Solved

Formatting Embedded Data with comma separators?


Hello,

There is an embedded data that I am outputting in a Text/Graphic box and in the question. For ease of reading, I would like to format this as a currency - or at the very least with thousand comma separators.

What would be the best way of handling this? I've looked around and couldn't find any code samples on this (most of the code samples involved formatting input fields, not embedded data).

Best answer by TomG

In html, create a span with an id that will contain the formatted number:
```
<span id="mynumber">mynumber</span>
```
Use JS to format the number and replace the span contents:
```
Qualtrics.SurveyEngine.addOnload(function() {
jQuery("#mynumber").text("$"+parseFloat("${e://Field/mynumber}").toFixed(2).toLocaleString());
});
```
View original

7 replies

PeeyushBansal
QPN Level 6 ●●●●●●
Forum|alt.badge.img+37
  • QPN Level 6 ●●●●●●
  • 1121 replies
  • August 22, 2018
You can store in embedded data in that format in which you want it to appear in question. When you pipe it in your question it will appear as formatted or as you passed in embedded variable.

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5797 replies
  • Answer
  • August 22, 2018
In html, create a span with an id that will contain the formatted number:
```
<span id="mynumber">mynumber</span>
```
Use JS to format the number and replace the span contents:
```
Qualtrics.SurveyEngine.addOnload(function() {
jQuery("#mynumber").text("$"+parseFloat("${e://Field/mynumber}").toFixed(2).toLocaleString());
});
```

  • Author
  • 8 replies
  • August 22, 2018
Thanks Tom! That's exactly what I'm looking for.


bansalpeeyush29: That's a good point - I had issues at first since this suggestion wouldn't work at all with a CSV - but then I realized Qualtrics uses TSV for importing as well.

mklubeck
Level 3 ●●●
Forum|alt.badge.img+8
  • Level 3 ●●●
  • 233 replies
  • July 2, 2021

TomG
Found this and loved your coding...BUT, I get the $ and the Decimal point, but not the comma? What am I missing?


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5797 replies
  • July 2, 2021

mklubeck
Level 3 ●●●
Forum|alt.badge.img+8
  • Level 3 ●●●
  • 233 replies
  • July 2, 2021

TomG Sorry, I went to the article, but I'm still perplexed. I couldn't decipher why I didn't get a comma? I'm in the US, using English as my browser language.


Forum|alt.badge.img+1
  • 10 replies
  • July 22, 2022

I think the "toFixed(2)" in the code was making it do decimals instead of commas. I tweaked to this and it worked:
Qualtrics.SurveyEngine.addOnload(function() {
  jQuery("#number").text("$"+parseFloat("${e://Field/NameofField}")
.toLocaleString("en-US"));
});


Leave a Reply