[Javascript] Number formatting

Chrome admin at chrome.me.uk
Thu Jun 29 15:06:34 CDT 2006


>At 12:26 PM 6/29/2006, Liam Rice wrote:
>>I've got a set of user input fields where a user is able to enter a
>>number.  The user can enter with or without commas/spaces for
>>separators.  I'm trying to remove them, but I keep getting the error
>>iNum.replace is not a function.  Anybody have any ideas?
>>
>>function cleanNumber(iNum) {
>>         iNum = iNum.replace(",","");
>>         iNum = iNum.replace(' ','');
>>         iNum = parseFloat(iNum);
>>
>>         return iNum;
>>}
>
>
>Since .replace() is a string function, try converting the number to a
>string first:
>
>         sNum = iNum.toString;
>         sNum = sNum.replace(",", "");
>         ...
>         iNum = parseFloat(sNum);

Well spotted :)... Sorry for providing a possibly misleading answer

Dan

-- 
http://chrome.me.uk




More information about the Javascript mailing list