The CreatorCon Call for Content is officially open! Get started here.

Convert String (Full UTF-8) display value to currency Format?

Community Alums
Not applicable

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

7 REPLIES 7

AbhishekGardade
Giga Sage

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.

find_real_file.png

Please mark as Correct Answer and Helpful, if applicable.
Thank You!
Abhishek Gardade
ServiceNow MVP 2020

Thank you,
Abhishek Gardade

Community Alums
Not applicable

Hi Asbhishek,

I tried with your code, but my bad, can i get the full code?

thanks

Mohit Kaushik
Mega Sage
Mega Sage

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 :

  1. function addCommas(commission_amt){
  2. commission_amt+= '';
  3. var x = commission_amt.split('.');
  4. var x1 = x[0];
  5. var x2 = x.length > 1 ? '.' + x[1] : '';
  6. var rgx = /(\d+)(\d{3})/;
  7. while (rgx.test(x1)) {
  8. x1 = x1.replace(rgx, '$1' + ',' + '$2');
  9. }
  10. return x1 + x2;
  11. }

 

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

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Community Alums
Not applicable

Hi Mohit,

 

but we need on change of field value.

any suggestion?

 

Appreciate your help.