Manage Learn to apply best practices and optimize your operations.

Remove commas from dollar amounts in JavaScript using a split

Have you ever tried to add up multiple fields with JavaScript, only to find out that the client entered a comma to separate thousands and millions? This causes JavaScript to drop all of the digits after the comma. SearchDomino.com member Mike Parman explains how to use the split command to extract the commas prior to adding the fields together.

VIEW MEMBER FEEDACK TO THIS TIP

Have you ever tried to add up multiple fields with JavaScript, only to find out that the client entered a comma to separate thousands and millions? This causes JavaScript to drop all of the digits after the comma. You can use the split command to extract the commas prior to adding the fields together.

Add the removeComma function to the JavaScript Header section of your form, then add the call to the function, onto the onBlur section. Now, when the client moves from one field to another, all commas will be removed from the field.

function removeComma(num) {
var temp1 = 0;
var xarray = num.split(",");
if ( xarray[2] != null ) {
   temp1 = xarray[0]+xarray[1]
+xarray[2]; return temp1 } 
else if ( xarray[1] != null ) {
          temp1 = xarray[0]
+xarray[1]; return temp1}
       else
{temp1 = xarray[0]; return temp1 }         
}

MEMBER FEEDBACK TO THIS TIP

I've found this works as well.

function removeComma(num) {
    var temp1 = num;
    for (i=1;i<3;i++) {  
// pick limit high enough to find all possible
commas
    temp1 = temp1.replace(",","");
    }
    return temp1;
}


—Michael N.

Do you have comments on this tip? Let us know.

Related information from SearchDomino.com:

Dig Deeper on JavaScript for Lotus Notes Domino

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close