currency and number formatter

een
Kilo Contributor

How do I format a currency field so that it displays 01000000 as $1,000,000.00

my code to display currently is

snipping-tool-code-sample.PNG

where cost is defined as a variable

I've looked at the server side script API and do not seem to be able to locate anything.

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Ian,



Replace line 15


as cost = equipment.cost. getCurrencyDisplayValue(); and you can remove line 16


View solution in original post

14 REPLIES 14

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Ian,



You may find below link helpful.


Scripting Currency and Price Fields - ServiceNow Wiki


Abhinay Erra
Giga Sage

Use getDisplayValue() method. Like current.<your currency field name>.getDisplayValue()


een
Kilo Contributor

Unfortunately in my case the value i'm displaying is derived by adding up multiple values, so the field/variable i'm wishing to display is not a field from a record but rather a variable that i've created in my method. Hope this makes sense. I've included the code snippet. I'm sure there probably is a simple answer, however i'm new to service now coding so still learning the API



snipping-tool-code-sample.PNG


Ian,



  you can use something like this


var currency_code=equipment.cost.getCurrencyCode();


cost= cost+ equipment.cost.getCurrencyValue();



Finally you can append both currency code and value



var final_cost= currency_code+' '+cost;