Convert String (Full UTF-8) display value to currency Format?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2020 12:08 AM
Hi Community,
I have a requirement to convert String (Full UTF-8) field values to currency value .
eg : Commission Amount = 10000000
Expected: 10,000,000
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2020 12:49 AM
Hello Rafmin,
var num = 10000000 ;
var currency = num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,') ;
gs.print(currency);
You can play around this regex if needed.
Please mark as Correct Answer and Helpful, if applicable.
Thank You!
Abhishek Gardade
ServiceNow MVP 2020
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2020 01:59 AM
Hi Asbhishek,
I tried with your code, but my bad, can i get the full code?
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2020 02:08 AM
Hi Rafmine,
You can do this for onSubmit Client script.
You can try the below code :
var commission_amt = g_form.getValue("<commision_amount_fieldbackend_name");
var exp= commission_amt.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
or you can create a function like this :
-
function addCommas(commission_amt){
-
commission_amt+= '';
-
var x = commission_amt.split('.');
-
var x1 = x[0];
-
var x2 = x.length > 1 ? '.' + x[1] : '';
-
var rgx = /(\d+)(\d{3})/;
-
while (rgx.test(x1)) {
-
x1 = x1.replace(rgx, '$1' + ',' + '$2');
-
}
-
return x1 + x2;
-
}
and in your expected value you can simple call this function
var exp =addCommas(commission_amt);
Please mark this answer correct if it resolved the query and mark it helpful too if it helped you at all
Thanks,
Mohit Kaushik
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2020 02:33 AM
Hi Mohit,
but we need on change of field value.
any suggestion?
Appreciate your help.