Re: convert string to number

From: Date: Mon, 17 Nov 2003 16:55:18 +0000
Subject: Re: convert string to number
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-169976@lists.php.net to get a copy of this message
From: "Jay Blanchard" <jay.blanchard@niicommunications.com> > From: "Diana Castillo" <diana@interhotel.com> > > > [snip] > > what is the easiest way to convert a string like this "1,300.99" to a > > number? > > [/snip] > > http://www.php.net/settype That'll just result in the number 1, though, since the conversion to "float" will stop at the comma. If you know that it's just going to be commas in there, a simple str_replace(',','',$number) will get rid of the commas. Then PHP's type juggling will take care of the rest for you and treat it like a FLOAT if it needs to be. Or you can then use settype() to ensure it's a float. ---John Holmes...

« previous php.general (#169976) next »