[Javascript] Number formatting

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


>Hi there everybody, I'm having a few issues with number formatting from
>an input field.
>
>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;
>}

Just a few guesses (I don't have time to research properly... sorry) but
maybe changing the lines to:

iNum = iNum.replace(/,/g,"");
iNum = iNum.replace(/\s/g,'');

May work?

Worth a try :)

Dan

-- 
http://chrome.me.uk




More information about the Javascript mailing list