- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2020 04:47 AM
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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2020 06:46 AM
Try this:
var Amount0 = current.variables.invoice_amount.toString();
var Amount1 = Amount0.replace(/[^\d\.]/g, '');
var Amount2 = Math.round(parseInt(Amount1));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2020 06:25 AM
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));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2020 06:39 AM
Tried with invoice_amount = 1,909.34
Amount0 return 1,909.34
Amount1 return undefined,
while Amount 2 return NaN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2020 06:43 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2020 06:46 AM
Try this:
var Amount0 = current.variables.invoice_amount.toString();
var Amount1 = Amount0.replace(/[^\d\.]/g, '');
var Amount2 = Math.round(parseInt(Amount1));