Page 1 of 1

formatting response from service placed on a label.

Posted: Thu Jan 24, 2013 3:31 pm
by Arcelio J. Fetizanan Jr.

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?


formatting response from service placed on a label.

Posted: Thu Jan 24, 2013 3:51 pm
by Maryna Brodina

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


formatting response from service placed on a label.

Posted: Thu Jan 24, 2013 3:55 pm
by Arcelio J. Fetizanan Jr.

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.


formatting response from service placed on a label.

Posted: Thu Jan 24, 2013 4:28 pm
by Maryna Brodina

JavaScript can be used to format the number


formatting response from service placed on a label.

Posted: Thu Jan 24, 2013 4:40 pm
by Maryna Brodina

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


formatting response from service placed on a label.

Posted: Thu Jan 24, 2013 5:11 pm
by Arcelio J. Fetizanan Jr.

Thanks. It worked. :-)