[Javascript] Number formatting

Liam Rice Liam.Rice at autodata.net
Thu Jun 29 15:38:58 CDT 2006


Yeah, it was because I passed a number.  Thanks for the help guys :).  

-----Original Message-----
From: javascript-bounces at LaTech.edu
[mailto:javascript-bounces at LaTech.edu] On Behalf Of Paul Novitski
Sent: Thursday, June 29, 2006 4:31 PM
To: JavaScript List
Subject: Re: [Javascript] Number formatting


At 01:03 PM 6/29/2006, joel.goldstick at columbuswebmakers.com wrote:
>I was thinking Javascript thinks its a string.  So I googled this here:

>http://www.siteexperts.com/tips/functions/ts23/page3.asp
>
>I think you could change the regex to /[, ]/ and it will work for you
>
>Remove Commas
>
>A user may enter a number separated by commas. You may wish to
>remove the commas before storing the number. A reformatting function 
>to do that would look like this:
>
>function removeCommas( strValue ) {
>   var objRegExp = /,/g; //search for commas globally
>   //replace all matches with empty strings
>   return strValue.replace(objRegExp,'');
>}


I believe it wasn't Liam's replacement logic that ran him aground, 
but rather the fact that he was probably passing his function a 
Number object to which he was attempting to apply a String object 
method.  Once that argument is converted to a string, I believe 
replace() would work, either using RegExp as you suggest or a string 
as Liam was doing.

P. 

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript



More information about the Javascript mailing list