title: Using parseFloat() or parseInt() and regex in JavaScript (converting a CSV file)
body: <p>I'm converting a CSV file to a local 2D array.  I wanted to know if there is a better way to convert strings to floats/int rather then using regex followed by a parseFloat() / parseInt.  </p>
  
  <p>Ideas / Suggestions?</p>
  
  <pre><code>// numex() - checkes to see if the string (str) is a number
  // returns number.valid (true||false) and number.value = (float||int||string)
  numex = function(str){
    number = {};
    number.valid = false;
    number.value = str;
    // if we see a number then convert it to a floating point or integer
    if((number.value.search(/[^0-9^\.^\$^\%^\-^\"^,^ ]+/) &lt; 0) &amp;&amp; str.length &gt; 0) {  
      number.valid = true;
      number.value = str.replace(/[^\-^0-9^\.]+/g, ''); // TODO add % coversion code for example if we see a 10% covert it to .1
      if(number.value.search(/[\.]/) &gt;= 0) {  
         number.value = parseFloat(number.value); // replace floating point
      } else {
         number.value = parseInt(number.value); // replace integers
      }
    }
    return number; // number.valid = true or false;
  }
  
  var num = numex("1.101");
  alert(num.value);
  </code></pre>