Money To Integer

[Total: 0    Average: 0/5]

This example will take dollar figures and convert them to integers.

Body Code:

function convertIt(_numString)
  var _returnValue="";
  var _array=_numString.split(""); /* make each character be in its own array slot */
  for(var i=0; i< _array.length;i++)
    /* if the character is not a $ or a space or a comma then take it */
    if(_array[i].search(/[$ ,]/) == -1)
	  /* this uses strings addition to catinate the value together */
	  /* the first value in an addition equation sets the type of opperation - here it is a string */
      _returnValue += _array[i].toString();
  /* this converts it to an integer */
var a = convertIt("75,000");
var b = convertIt("$75,000");
var c= convertIt("$ 75,000");

Times Viewed: 3

Leave a Reply

Your email address will not be published. Required fields are marked *