Re: Stripping Decimals

From: Date: Tue, 04 Nov 2003 15:51:47 +0000
Subject: Re: Stripping Decimals
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-168476@lists.php.net to get a copy of this message
Thanks! Works like a charm. Ed On Tue, 4 Nov 2003, CPT John W. Holmes wrote: > From: "Ed Curtis" <ed@homes2see.com> > > I currently use number_format() and str_replace() to remove a "," or > > "$" > > if entered and reformat it as a price for an item. I've asked the > > user not to use decimals but some still do. How do I remove a decimal and > > anything after from a number in a varable? > > $new_number = preg_replace('/\.[0-9]+/','',$old_number); > > I would do that first, then a > > $new_number = preg_replace('/[^0-9]/','',$new_number); > > afterwards to remove anything that's not a number from the string. > > ---John Holmes... > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#168476) next »