java code for showing decimal number form between text by 2 decimal places | XM Community
Skip to main content

I need a Java scripts which can show the generated decimal form number between text in preview just by two decimal part not more.

"You bought a product for 1.6358959564557056 since that was less than or equal to the price you offered to 4" this is the exact text qualities are going to show to participants when they answer the question and I am adding a java code in question part to make the 1.6358959564557056 to just 1.63


If your html is:

You bought a product for <span class="amt">1.6358959564557056</span> since that was less than or equal to the price you offered to 4

Then you can use this JS:

var amt = jQuery("#"+this.questionId+" .amt");
amt.text(Number(amt.text()).toFixed(2));

 


If your html is:

You bought a product for <span class="amt">1.6358959564557056</span> since that was less than or equal to the price you offered to 4

Then you can use this JS:

var amt = jQuery("#"+this.questionId+" .amt");
amt.text(Number(amt.text()).toFixed(2));

I tried the code but it is not working, let me explain more, “1.6358959564557056” is a number which is Generated randomly by computer as i sat is as embedded data in flow survey: product_price= ${rand://float/1:5}, and As i can not put anything else unless math logic in flow survey i need a java code to reduce the decimal place to 2 places for me because as you can see when participants see this message “You bought a product for 1.6358959564557056 since that was less than or equal to the price you offered to 4” in preview is annoying.

 


We can use Math operation as show below:

product_price - ${rand://float/1:5}

product_price_round - $e{ round( e://Field/product_price , 2 ) }

 


If your html is:

You bought a product for <span class="amt">1.6358959564557056</span> since that was less than or equal to the price you offered to 4

Then you can use this JS:

var amt = jQuery("#"+this.questionId+" .amt");
amt.text(Number(amt.text()).toFixed(2));

I tried the code but it is not working, let me explain more, “1.6358959564557056” is a number which is Generated randomly by computer as i sat is as embedded data in flow survey: product_price= ${rand://float/1:5}, and As i can not put anything else unless math logic in flow survey i need a java code to reduce the decimal place to 2 places for me because as you can see when participants see this message “You bought a product for 1.6358959564557056 since that was less than or equal to the price you offered to 4” in preview is annoying.

 

Did you try it with this html?

You bought a product for <span class="amt">${e://Field/product_price}</span> since that was less than or equal to the price you offered to 4

 


Leave a Reply