how to get currency2 value without including the currency symbol

daikhi haithem
Tera Expert

Hello

i want to know how to get currency2 value without including the currency symbol

 

"EUR;10"

7 REPLIES 7

Weird
Mega Sage

Depending on the context you could do some other things, but just for that example lets say your currency is stored in variable "currency".
You could just try something like this

var currency = "EUR;10";
var price = currency.split(";")[1];

gs.info(price);

 Here we have the currency value stored in a variable and we use split(";") to create an array or currency where each value is separated by the semicolon. This results in an array like ["EUR","10"]. By adding [1] we tell that we want the value in second index, which would be the actual numerical price.


If you have a currency symbol in the resulting value, you can also use .substring(1) to remove the first character.
So for example €10 would become 10.

daikhi haithem
Tera Expert

I thought there was a JavaScript method to do it directly because I'm looking for the best practice to build my code

Well, it depends on how you're getting the price. I assumed you had the currency as a string, but if you have the currency field, then there are few things you can do.
Below's a list of scripts and their results. 

Price 88USD and script run as user who sees euros.
current.price: 80.86
current.price.getReferenceCurrencyCode(): USD
current.price.getReferenceDisplayValue(): USD88.00
current.price.getReferenceValue(): 88
current.price.getSessionCurrencyCode(): EUR
current.price.getSessionDisplayValue(): €80.86
current.price.getSessionValue(): 80.86
current.price.getCurrencyCode(): USD
current.price.getCurrencyDisplayValue(): USD88.00
current.price.getCurrencyString(): EUR;80.86
current.price.getCurrencyValue(): 88

 

Hello....

can you elaborate on this method, like i have a table accounts with a field 1-30 which is a 'FX CURRENCY' type and contains values like $157,000 ...... etc , now i want to display this value in a vertical bar component but cant pass this value to it.......i tried doing 

var acc = new GlideRecord(input.table);
var gDotWalking = acc.getDisplayValue('u_1_30');

{
"assignment_group": "Current",
// "value": acc.getValue('current')
"value": gDotWalking
},
now this returns me this result
{
"assignment_group": "Current",
"value": "$157,500.00"
},
and i want to get the result as = "value" : 157500

can you help me with the code or approach to get this result.
Thank You.