Arcelio J. Fetizanan Jr.
Posts: 0
Joined: Wed May 16, 2012 1:00 pm

formatting response from service placed on a label.

I have a response from a service which contains a number with decimal places. I'm displaying it as an array using a label. My question is how do I convert it to currency before displaying it in the label so that the user will see the formatted value already?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

formatting response from service placed on a label.

Hello! Could you clarify your question? Please post some part of response you get and some example how it should look like?

Arcelio J. Fetizanan Jr.
Posts: 0
Joined: Wed May 16, 2012 1:00 pm

formatting response from service placed on a label.

ex. I received a response from the service, 12345.053. I save it in a label. But I want it to be displayed as $12,345.05

I tried putting it in the add javascript in the mapping screen but it did not work.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

formatting response from service placed on a label.

JavaScript can be used to format the number

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

formatting response from service placed on a label.

Add this code on mapping:

codefunction formatMoney (n) {
var c = 2, /decimals count/
d = ".",/decimal separator/
t = ",", /thousands separator/
s = n < 0 ? "-" : "",
i = parseInt(n = Math&#46;abs(+n || 0)&#46;toFixed(c)) + "",
j = (j = i&#46;length) > 3 ? j % 3 : 0;
return '$' + s + (j ? i&#46;substr(0, j) + t : "") + i&#46;substr(j)&#46;replace(&#47;(\d{3})(?=\d)&#47;g, "$1" + t) + (c ? d + Math&#46;abs(n - i)&#46;toFixed(c)&#46;slice(2) : "");
};
var formattedValue = formatMoney(value);
element&#46;html(formattedValue);
return formattedValue;/code

Return to “Issues”