How should I convert a number to either float or integer, if I don't know which one it is?
<p>I'm working on a program that reads in users input as a string, which includes reading in some numbers and operators.</p>

<p>I'm now trying to determine how to parse a string which I know to be a number but I don't know if it is a float or an integer.</p>

<p>I have a few ideas:</p>

<pre><code>function parseNumber(number)
{
    if (number % 1 == 0)
        return parseInt(number);
    else 
        return parseFloat(number);
}
</code></pre>

<p>or</p>

<pre><code>function parseNumber(number)
{
    if (number.indexOf(".") != -1)
        return parseFloat(number);
    else
        return parseInt(number);
}
</code></pre>

<p>or</p>

<pre><code>function parseNumber(number)
{
    if (!number.matches(/([0-9]+.[0-9]+)/))
        return parseInt(number);
    else
        return parseFloat(number);
}
</code></pre>

<p>And I can think of a few other ways.</p>

<p>Which way seems to be the best?</p>
