Re: changing strings to float vars
| From: | Steve Edberg | Date: | Mon, 15 Jan 2001 22:21:57 +0000 |
| Subject: | Re: changing strings to float vars | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-34706@lists.php.net to get a copy of this message | ||
At 4:28 PM -0500 1/15/01, bill wrote:
Sometimes clients put a dollar sign "$" in a form that only needs a number (like "1.50"). Is there a way to take a post variable and automatically convert it to a float value, stripping off any non-numeric characters? I tried doubleval() without success and I can't use intval() because it has decimals. kind regards,$SanitizedNumber = ereg_replace('[^0-9.]', '', $NumberString); If you really need to make this a float variable, then you can add $Number = (float)$SanitizedNumber; although in most cases PHP handles type conversion correctly on-the-fly. - steve +--- "They've got a cherry pie there, that'll kill ya" ------------------+
| Steve Edberg University of California, Davis | | sbedberg@ucdavis.edu Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ |+-------------------------------------- FBI Special Agent Dale Cooper ---+