note 43262 added to function.floatval

From: Date: Tue, 15 Jun 2004 23:00:11 +0000
Subject: note 43262 added to function.floatval
Groups: php.notes 
Request: Send a blank email to php-notes+get-71124@lists.php.net to get a copy of this message
Easier-to-grasp-function for the ',' problem. function Getfloat($str) { if(strstr($str, ",")) { $str = str_replace(".", "", $str); // replace dots (thousand seps) with blancs $str = str_replace(",", ".", $str); // replace ',' with '.' } if(preg_match("#([0-9\.]+)#", $str, $match)) { // search for number that may contain '.' return floatval($match[0]); } else { return floatval($str); // take some last chances with floatval } } echo Getfloat("$ 19.332,35-"); // will print: 19332.35 ---- Manual Page -- http://www.php.net/manual/en/function.floatval.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+43262 Delete -- http://master.php.net/manage/user-notes.php?action=delete+43262&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+43262&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#71124) next »