Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Numeric with decimal point

Status
Not open for further replies.

jmcg

Technical User
Jun 30, 2000
223
GB
I knwo little about javascipt and found this code elsewhere and looking to try to tweek.
It works fine in changing the value entered to numbers only but need to allow for a decimal place.
Is it possible to change this code to allow for a . decimal
Code:
function toNumber(checkString)
{
    newString = "";    // REVISED/CORRECTED STRING
    count = 0;         // COUNTER FOR LOOPING THROUGH STRING

    // LOOP THROUGH STRING CHARACTER BY CHARACTER
    for (i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i+1);

        // ENSURE CHARACTER IS AN NUMBER
        if ((ch >= "0" && ch <= "9") || (ch = "")){
            newString += ch;
        }
    }

    return newString;
}
 
Thanks BillyRay for the parseFloat, looks like the winner
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top