Re: Stripping Decimals

From: Date: Tue, 04 Nov 2003 15:45:55 +0000
Subject: Re: Stripping Decimals
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-168475@lists.php.net to get a copy of this message
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...

« previous php.general (#168475) next »