Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Remove comma from string

tsoct
Tera Guru

Hi all,

I have the requirement where the amount in catalogue item must be in format xx,xxxx.xx .... To route the approval base on the amount, I need to remove the comma.

With the script below, it is giving me NaN error. Can anyone help on this?

var Amount0 = current.variables.invoice_amount;
var Amount1 = Amount0.replace(/[^\d.]/g, '');
var Amount2 = Math.round(Amount1);

 

 

1 ACCEPTED SOLUTION

Try this:

var Amount0 = current.variables.invoice_amount.toString();
var Amount1 = Amount0.replace(/[^\d\.]/g, '');
var Amount2 = Math.round(parseInt(Amount1));

View solution in original post

8 REPLIES 8

Try logging the values. Also try parsing to int:

var Amount0 = current.variables.invoice_amount;
var Amount1 = Amount0.replace(/[^\d\.]/g, '');
var Amount2 = Math.round(parseInt(Amount1));

Tried with invoice_amount = 1,909.34

Amount0 return 1,909.34

Amount1 return undefined,

while Amount 2 return NaN

For me that is working:

find_real_file.png

 

Result:

find_real_file.png

Try this:

var Amount0 = current.variables.invoice_amount.toString();
var Amount1 = Amount0.replace(/[^\d\.]/g, '');
var Amount2 = Math.round(parseInt(Amount1));