note 39379 added to function.floatval

From: Date: Mon, 26 Jan 2004 20:45:39 +0000
Subject: note 39379 added to function.floatval
Groups: php.notes 
Request: Send a blank email to php-notes+get-64215@lists.php.net to get a copy of this message
floatval() does not work with "$35,234.43", as it could not handle the '$' and the ','. The following takes care of all values, such that only numeric and the decimal sign are input into floatval(). (It probably shows I'm an old 'c' guy)...this function only lightly tested. function strtflt($str) { $il = strlen($str); $flt = ""; $cstr = ""; for($i=0;$i<$il;$i++) { $cstr = substr($str, $i, 1); if(is_numeric($cstr) || $cstr == ".") $flt = $flt.$cstr; } return floatval($flt); } Richard Vickers vickers@hotpop.com ---- Manual Page -- http://www.php.net/manual/en/function.floatval.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39379 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39379&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39379&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#64215) next »