How to round an embedded data variable? | XM Community
Skip to main content

Hi!
I've made the following embedded data variable: ${gr://SC_6M4lPMHbDTjS885/WeightedMean}
I'm trying to figure out how I can get this variable to round to 2, and I've seen some other pages about the same topic, but still seem to be doing something wrong...thoughts?
I tried this and it's not working : ${ round ( gr://SC_6M4lPMHbDTjS885/WeightedMean , 2) }

I think the Qualtrics round function only works on integers. You can use this small function.
Place it inside the Javascript of empty descriptive text question after the scoring question. It will create an embedded variable called rounded_mean
It needs a page break before and after it.
Qualtrics.SurveyEngine.addOnload(function()
{
        function round(value, decimals) {
            return Number(Math.round(value+'e'+decimals)+'e-'+decimals);
        }
        x = round("${gr://SC_6M4lPMHbDTjS885/WeightedMean}",2);
        Qualtrics.SurveyEngine.setEmbeddedData("rounded_mean",x);
        //Click next button so no waiting here
        this.clickNextButton();
});


Leave a Reply