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

SearchWindowsServer

Search400

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/Search400.com community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury

SearchDataCenter

SearchContentManagement

Close